このスクリプトを空のGameObjectにつけており、他の2つのオブジェクトの内1つが相手のオブジェクトに衝突している時は、IsLandingにtrueを返すようにしたいのですが、引数をどう扱えば良いのか分かりません。
そもそもOnCollisionEnterではなく他の関数を使用するのでしょうか?
###該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class LauncherController : MonoBehaviour 6{ 7 8 public GameObject obj; 9 public float rotSpeed = 180f; 10 11 public GameObject LauncherPushRod; 12 public float JumpSpeed = 12.0f; 13 public bool IsLanding; 14 public GameObject CoinButton; 15 //回転用 16 Vector2 sPos; 17 //タッチした座標 18 Quaternion sRot; 19 //タッチした時の回転 20 float wid, hei; 21 //スクリーンサイズ 22 float tx, ty; 23 //変数 24 25 26 // Use this for initialization 27 void Start () 28 { 29 wid = Screen.width; 30 hei = Screen.height; 31 } 32 33 // Update is called once per frame 34 void Update () 35 { 36 if (Input.touchCount == 1) { 37 Touch t1 = Input.GetTouch (0); 38 if (t1.phase == TouchPhase.Began) { 39 sPos = t1.position; 40 sRot = obj.transform.rotation; 41 } else if (t1.phase == TouchPhase.Moved || t1.phase == TouchPhase.Stationary) { 42 tx = (t1.position.x - sPos.x) / wid; 43 ty = (t1.position.y - sPos.y) / hei; 44 obj.transform.rotation = sRot; 45 obj.transform.Rotate (new Vector3 (0, -rotSpeed * tx, 0), Space.World); 46 } else if (IsLanding && CoinButton.GetComponent<CoinButton> ().TouchCoinButton () == false) { 47 if (ty <= 0 && t1.phase == TouchPhase.Ended) { 48 IsLanding = false; 49 LauncherPushRod.GetComponent<Rigidbody> ().velocity = Vector3.up * JumpSpeed * Mathf.Abs (ty); 50 } 51 } 52 } 53 } 54 55 public void OnCollisionEnter (Collision collision) //ここの引数でしょうか?分かりません。 56 { 57 if (collision.gameObject.tag == "table") { 58 IsLanding = true; 59 } 60 } 61}
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/19 16:40