簡體   English   中英

碰撞不適用於 Unity 2D 中的標簽

[英]Collisions not working with tags in Unity 2D

我一直在嘗試創建一個游戲,一旦您點擊“重復”符號,您就必須返回到第一個重復符號的位置,即在此處輸入圖片說明

一旦玩家點擊“結束-重復標志”,他們將返回“開始-重復標志”,但只有一次然后他們將繼續關卡,但由於某種原因,即使是剛體,游戲也不會注冊符號被添加

void OnCollisionEnter(Collision collision){
        
        if(state != State.alive || collisionsDisabled){ return; }
        
        switch(collision.gameObject.tag){
            case "Win":
                print("win");
                StartSucessSequence();
                break;
            case "Lose":
                StartDeathSequence();
                break;
            case "StartRepeat":
                print("touched");
                OnTriggerEnter(other);
                break;
            default:
                StartDeathSequence();
                break;    
        }
    }

void OnTriggerEnter(Collider other){
       // if startrepeat is touched go to endrepeat
       //for only once
        StartRepeat = GameObject.FindWithTag("StartRepeat");
        EndRepeat = GameObject.FindWithTag("EndRepeat");

       for (int i = 0; i < 1; i++){
           if(other.gameObject.tag == "StartRepeat") {
               other.transform.position = EndRepeat.transform.position;
               other.transform.rotation = EndRepeat.transform.rotation;
           }
       }
    }

我的“Lose”標簽工作正常,但我的“Win”或“StartRepeat”不行在此處輸入圖片說明

我在想這可能是 Z 軸的問題,因為其他一切都與障礙物相似(“輸”——這是紅色音符)

如果還有什么需要請告訴我

首先,如果您想使用 2d 剛體,請將您的 OnCollision 和 OnTrigger 更改為 2d ,那么我建議您不要自己調用 OnTrigger 並創建另一個包含 OnTrigger 代碼的方法並使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM