すみません、質問させてください。
メインカメラの設定をプレイヤーに追尾するようにしています。
具体的には、スタート関数でFindGameObjectWithTag()でプレイヤーTagのオブジェクトを認識させて、カメラを追尾させています。
で、障害物に当たった時に、プレイヤーをdestroy()で消去し、ゲームオーバーとするんですが、
ゲームオーバー時に「playerTagを見つけられません」的なエラーが出てしまいます。
当然と言えば当然ですが、このような場合の対策としてどのようなものが考えられますか?
良い知恵をかしてください。よろしくお願いします。
以下追記(よろしくお願いします)
c#
1using UnityEngine; 2using System.Collections; 3 4public class CameraControl : MonoBehaviour {//カメラスクリプト 5 6 // プレイヤー. 7 private GameObject player = null; 8 9 public Vector3 offset; 10 11 // Use this for initialization 12 void Start () { 13 14 // プレイヤーのインスタンスを探しておく. 15 this.player = GameObject.FindGameObjectWithTag("Player"); 16 17 this.offset = this.transform.position - this.player.transform.position; 18 } 19 20 // Update is called once per frame 21 void Update () { 22 23 // プレイヤーと一緒に移動. 24 this.transform.position = new Vector3(player.transform.position.x + this.offset.x, player.transform.position.y + this.offset.y, this.transform.position.z); 25 26 } 27}
C#
1 2using UnityEngine; 3using System.Collections; 4 5 6 7public class PlayerMove : MonoBehaviour 8{ 9 10 11 public GameObject explosion; //爆発エフェクト 12 private bool isQuitting = false; 13 14 // Use this for initialization 15 void Start() 16 { 17 } 18 19 // Update is called once per frame 20 void Update() 21 { 22 23 } 24 void OnCollisionEnter(Collision col)//ぶつかった時実行 25 { 26 27 28 if (col.gameObject.tag == "Ground")//地面と接触 29 { 30 gameover(); 31 32 33 } 34 } 35 void gameover() 36 {//ゲームオーバー処理 37 Ui.is_gameOver = true; 38 Destroy(this.gameObject); 39 40 } 41 void OnApplicationQuit() 42 { 43 isQuitting = true; 44 } 45 46 void OnDestroy() 47 { 48 if (!isQuitting) 49 { 50 GameObject.Instantiate(explosion, transform.position, Quaternion.identity); 51 } 52 } 53}
再現するためのソースコードを追記してください。
回答1件
あなたの回答
tips
プレビュー