1

Unity の使用は初めてで、スプライトを衝突トリガーとして使用しようとしています。しかし、私の OnTriggerEnter2d はトリガーしません。情報は次のとおりです。

主人公情報 主人公情報

トリガー情報として使用される衝突スプライト トリガーとしてのスプライトの使用

メインキャラクターに添付された newPlatformRow スクリプトのコード

using UnityEngine;
using System.Collections;

public class NewPlatformRow : MonoBehaviour {

    private float leftPlatformX = -12f; //de unde incepe platforma din stanga
    private float rightPlatformX = 3.123f; // de unde incepe platforma din dreapta
    private float rowDistance = -5f; //distanta dintre randurile de platforme

    private float leftPlatformWidth; //acestea vor fi calculate random pt fiecare rand nou
    private float rightPlatformWidth;





    // Use this for initialization
    void Start ()
    {
        //Debug.Log("why wont you work ;_;");

    }

    // Update is called once per frame
    void Update () {
        //Debug.Log("why wont you work ;_;");
    }


    void OnTriggerEnter2d(Collider2D other)
    {

        Debug.Log("why wont you work ;_;");

        if (other.gameObject.CompareTag("newPlatformRow"))
        {

            Vector3 newLeftPlaformPosition;
            Vector3 newRightPlaformPosition;

            var leftPlatform = GameObject.Find("LeftWallPlatform");
            var rightPlatform = GameObject.Find("RightWallPlatform");

            newLeftPlaformPosition = new Vector3(leftPlatform.transform.position.x, leftPlatform.transform.position.y + rowDistance, leftPlatform.transform.position.z);
            newRightPlaformPosition = new Vector3(rightPlatform.transform.position.x, rightPlatform.transform.position.y + rowDistance, rightPlatform.transform.position.z);

            Transform leftPlatformTransform = leftPlatform.transform;
            Transform rightPlatformTransform = rightPlatform.transform;

            Transform newLeftPlatform = Instantiate(leftPlatformTransform, newLeftPlaformPosition, leftPlatformTransform.rotation) as Transform;
            Transform newRightPlatform = Instantiate(rightPlatformTransform, newLeftPlaformPosition, rightPlatformTransform.rotation) as Transform;

            newLeftPlatform.parent = leftPlatformTransform.parent;
            newRightPlatform.parent = rightPlatformTransform.parent;

        }
    }
}

ではありません: Debug.Log("why wont you work ;_;");呼び出されることはありません

完全なシーン情報: ここに画像の説明を入力

何が間違っているのか本当にわかりません。ありがとう

4

2 に答える 2

4

スペルを間違えたようですvoid OnTriggerEnter2d(Collider2D other)。実際には である必要がありますOnTriggerEnter2D。ここで大文字のDに注意してください。トリガーとコライダーの名前はすべてOnMouseDown()同じように機能します。大文字と小文字を区別して、まったく同じ名前にする必要があります。

于 2015-12-29T16:01:24.210 に答える