How do I make it so one player activates one thing and another activates another thing?

So heres how it is. I’m making a game in which there are two players. when one activates a trigger I want it so that he loads level 2 and the other activates level 3. How do I do that with only 1 trigger?

2 Answers

2

You will have to tag the players with their own tags (or just use won of the tags the game comes with respawn, player, etc) and then check it within the function

function OnTriggerEnter(object : Collider)
    if(object.CompareTag(Player1) == true) {
         Application.LoadLevel("level 2");
    }
    if(object.CompareTag(Player2) == true) {
         Application.LoadLevel("level 3");
    }

you may want to change the tags or the level names but this should work

Wow thanks! How did I not think about that? I totally forgot about tags! Helped me alot man.

OnTriggerEnter(Collider other)
{
if(other.gameObject.name == “Player1”)
Application.Load(“Level2”);
elseif(other.gameObject.name == “Player2”)
Application.Load(“Level3”);
}

A more robust solution would be to have a unique identifier in the class itself and get a reference to the player script and then do an if against the name property, but the above will work as a starting point.

Projects varies. Those are all situational. If like simple rotation, script can adjust rotate speed and call script in Update can modifed by &frameCount which can reduce cost per second.