詳談Unity物件實體化_心智圖擴展

何謂   「實體化」 ??



一般在遊戲中比方說

突然生成的   哥布林  或是  炸彈


而且一次一整群


一次是一個Group 這樣的生成





我們來看一下在Unity中

他的心智圖擴展






目前第一版程式.  預設生成一個物件在場景離世界座標一米高處

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateBox : MonoBehaviour {
    public GameObject goPrefab;

    // Use this for initialization
    void Start () {
        GameObject.Instantiate (goPrefab, Vector3.up, Quaternion.identity);
        //在世界(0,0,0)上方一米處生成, 使用identity無旋轉的屬性
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}




使用隨機位置生成物件

我們來看一下 心智圖擴展





第二版程式.按下Space隨機生成物件


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateBox : MonoBehaviour {
    public GameObject goPrefab;

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            Vector3 position = new Vector3 (Random.Range(-9.0f, 9.0f), Random.Range(-3.0f, 3.0f), Random.Range(-9.0f, 9.0f));
            GameObject.Instantiate (goPrefab, position, Quaternion.identity);        
        }
    }
}




按下  空白按鈕後效果










留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients