Unityについてです。
下記のコードの元、特定のオブジェクト(Warp1)に触れた時、Debug.Logを出力したいのですが、Debug.Logが出力しません。なぜですか?わかる方、回答お願いします。
コードで、問題の部分
void OnTriggerStay2D(Collider other) { Debug.Log(other.gameObject.name); if (other.gameObject.name == "Warp1") { Debug.Log("sss"); } } ``` コード全体 ``` using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { Animator animator; float movespeed; //PlayerPrefs.SetInt("Data", 10); public int S = 0; // Start is called before the first frame update void Start() { this.animator = GetComponent<Animator>(); } // Update is called once per frame void Update() { transform.rotation = Quaternion.Euler(0, 0, 0); if (S == 0) { if ((Input.GetKey(KeyCode.UpArrow)) || (Input.GetKey(KeyCode.DownArrow)) || (Input.GetKey(KeyCode.RightArrow)) || (Input.GetKey(KeyCode.LeftArrow))) { movespeed = 0.125f; this.animator.speed = (movespeed / 0.1f); } else { movespeed = 0; this.animator.speed = (movespeed / 0); } } if (Input.GetKey(KeyCode.UpArrow)) { animator.SetInteger("PL", 1); transform.Translate(new Vector2(0, movespeed)); } else { if (Input.GetKey(KeyCode.DownArrow)) { animator.SetInteger("PL", 2); transform.Translate(new Vector2(0, 0 - movespeed)); } else { if (Input.GetKey(KeyCode.RightArrow)) { animator.SetInteger("PL", 3); transform.Translate(new Vector2(movespeed, 0)); } else { if (Input.GetKey(KeyCode.LeftArrow)) { animator.SetInteger("PL", 4); transform.Translate(new Vector2(0 - movespeed, 0)); } } } } } void OnTriggerStay2D(Collider other) { Debug.Log(other.gameObject.name); if (other.gameObject.name == "Warp1") { Debug.Log("sss"); } } } ``` オブジェクトWarp1は、TileMapのオブジェクトで、親オブジェクトはGridです。 Warp1は、IsTriggerにチェックを入れているのですり抜ける状態です。 名前はコピペなので間違ってはいないと思います。 また、このスクリプトがアタッチされているオブジェクトは、十字キーによって動くオブジェクトです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。