/実装したいこと/
特定のオブジェクトを一定の時間で破棄する仕様を実装したい。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Player : MonoBehaviour { 6 7 8 public float jumpPower;//Player跳躍力変数 9 public float DestroyTsumikiTimer;//積み木削除時間計測用変数 10 public GameObject tsumikiPrefabs;//積み木Prefabs格納 11 12 private Rigidbody2D rg2d;//コンポーネント取得用変数 13 public float speed ; 14 private float moveX = 0f; 15 private float moveY; 16 private Rigidbody2D rb; 17 // Use this for initialization 18 void Start() 19 { 20 rb = GetComponent<Rigidbody2D>(); 21 } 22 23 private void Update() 24 { 25 moveX = Input.GetAxis("Horizontal") * speed; 26 moveY = Input.GetAxis("Vertical") * speed; 27 Vector3 direction = new Vector2(moveX, 0); 28 } 29 30 private void FixedUpdate() 31 { 32 rb.velocity = new Vector3(moveX, 0); 33 tsumiki(); 34 35 } 36 private void tsumiki() 37 { 38 //var P_pos = transform.localPosition.x; 39 if (Input.GetKey(KeyCode.Space)) 40 { 41 Debug.Log("出た!"); 42 Instantiate(tsumikiPrefabs, this.transform.localPosition, Quaternion.identity); 43 Destroy(tsumikiPrefabs, DestroyTsumikiTimer); 44 } 45 } 46} 47
一定時間が経つと破棄されるオブジェクトを用意しようとしているのですが、実装が出来ません。
Destroy関数の明記している位置が悪いのか、そもそものスクリプトが駄目なのか教えていただきたいです・・・。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。