Can't use SetActive (true) on collision
Hi i'm new to coding and i could use some help. I'm trying to switch between characters on collision and i have created the following script:
public GameObject Player1;
public GameObject Player2;
public GameObject Player3;
public GameObject Player4;
public int playerChanger = 1;
// Use this for initialization
void Start()
{
Player4.SetActive(false);
Player3.SetActive(false);
Player2.SetActive(false);
Player1.SetActive(true);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Burger")
{
Destroy(collision.gameObject);
playerChanger++;
Debug.Log(playerChanger);
if (playerChanger == 2)
{
Player1.SetActive(false);
Player2.SetActive(true);
Debug.Log("fat2");
}
if (playerChanger == 3)
{
Player2.SetActive(false);
Player3.SetActive(true);
Debug.Log("fat3");
}
if (playerChanger == 4)
{
Player3.SetActive(false);
Player4.SetActive(true);
Debug.Log("fat4");
}
}
When i start the game the player 1 is active as it should be, however it won't change to player 2 on collision with the "burger"-tagged object.
My hiararchy is a MetaPlayer empty with each player empty as children. The script is applied to the MetaPlayer.
Your answer
Follow this Question
Related Questions
,How to make a Univers Sand box Collision type thing.. [HELP PLZ] 0 Answers
Trying to figure out how to properly use my CircleCast Detection in my 2D Prototype 0 Answers
rb.velocity.y sometimes requires stopping on x axis as well. 0 Answers
how do i collide and kill the enemy while pressing space Unity 5 C# 2 Answers
How to keep gameObjects set as triggers to only trigger once, even after a scene reload? 0 Answers