Paige
Paige

Reputation: 169

Collisions not working with tags in Unity 2D

I've been trying to create a game where once you hit the 'repeat' symbol you have to return to the position of the first repeat symbol i.e enter image description here

once the player hits the "end-repeat sign" they'll return to the "begin-repeat sign" but only once then they'll continue the level, but for some reason the game won't register the symbols even when a rigidbody is added

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;
           }
       }
    }

my "Lose" tag is working perfectly, but not my "Win" or "StartRepeat" enter image description here

I was thinking perhaps it's an issue with the Z-axis cause everything else is similar to the obstacle ("Lose" - which is the red notes)

if anything else is needed please tell me

Upvotes: 0

Views: 351

Answers (1)

sajad maghsoodi
sajad maghsoodi

Reputation: 11

First of all if you want to use a 2d rigidbody change your OnCollision and OnTrigger to 2d , then i suggest that you don't call OnTrigger by your own and create another method that contains the OnTrigger Code and use that instead.

Upvotes: 1

Related Questions