衝突判定のあとに
- 衝突してきたオブジェクトを消す
- 新しいオブジェクトを生成する
- 画面の奥に投げる
という処理をしようとしています。
c#
1public GameObject AttackBallPrefab; 2 3 public void OnTriggerEnter(Collider other) 4 { 5 Destroy(other.gameObject); 6 7 bool triggerFlag = true; 8 if (triggerFlag) 9 { 10 triggerFlag = false; 11 GameObject atk = Instantiate(AttackBallPrefab) as GameObject; 12 Rigidbody rb = atk.GetComponent<Rigidbody>(); 13 atk.transform.position = transform.position; 14 Vector3 force = new Vector3(0.0f, 500.0f, 450.0f); 15 rb.AddForce(force); 16 } 17 } 18 19 void Update () { 20 if(Input.GetKeyDown(KeyCode.LeftArrow)) 21 { 22 this.transform.position = new Vector3(-1.0f, 0.45f, -8.5f); 23 } 24 else if(Input.GetKeyDown(KeyCode.DownArrow)) 25 { 26 this.transform.position = new Vector3(0.0f, 0.45f, -8.5f); 27 } 28 else if(Input.GetKeyDown(KeyCode.RightArrow)) 29 { 30 this.transform.position = new Vector3(1.0f, 0.45f, -8.5f); 31 } 32 }
一応オブジェクトは生成されているみたいなのですが、オブジェクトを投げるタイミングが
このスクリプトを持っているオブジェクトが移動したあとになってしまいます。
判定の直後に投げるにはどうすればよいのでしょうか?
また、他に良い方法があれば教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー