面向元件程式設計之Unity 6.怎樣複製遊戲物體 關鍵字:time//Instantiate/Debug
阿新 • • 發佈:2018-12-26
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TransformFeng2 : MonoBehaviour { //bullet public GameObject cubebullet; //發射點 public Transform tra; //時間 float Timer = 0; // Update is called once per frame void Update() { //每幀加一幀的時間 Timer += Time.deltaTime; //每兩秒複製一次 if (Timer > 2) { //<>泛型,cubebullet複製物體,一般為預設體。tra.position複製座標,tra.rotation複製角度 GameObject bullet = Instantiate<GameObject>(cubebullet, tra.position, tra.rotation); Timer = 0; Debug.Log("每隔兩秒複製一次"); } } }