Compare tags in UnityScript

We are creating a 3D game and right now I am stuck with an issue where I need to compare multiple tags in order to activate or deactivate a trigger that sends the player back to the respawn position.

Currently this is the code:

#pragma strict

var spawnPoint : GameObject;

function OnTriggerStay ( other : Collider )
{
    if (other.tag == "Player" && other.tag != "Ball")
    {
        other.tag == "Player";
        other.gameObject.transform.position = spawnPoint.transform.position;
    }

    else if ( other.tag == "Ball" && other.tag == "Player" )
    {

    }
}

      

I'm not sure how to fix this in order to do the following:

If the player touches the trigger without bumping into it, the player returns to it. This should make it feel like the particles are killing you. If the player touches the trigger when the ball hits it, nothing happens to the player and the player is free to pass.

What we want to do is we want to pump the ball over the geyser so that it covers it, and if the geyser is not covered and the player tries to go through it, the player will reappear.

We also tried with a different code, and while it allows the ball to pass, it prevents the player from doing so. Even after the ball has been placed.

#pragma strict

var spawnPoint : GameObject;

function OnTriggerStay ( other : Collider )
{
    if (other.tag == "Ball")
    {
        other.enabled = false;
    }

    else if (other.tag == "Player")
    {
        other.gameObject.transform.position = spawnPoint.transform.position;
    }
}

      

+3


source to share


1 answer


So, I believe your problem is that you are only checking the first collision when using this function. So what happens when you get the value of neither the player, nor the ball, not both. You need to save all collisions so you can compare all of them. For that you can follow the generals of this documentation. http://docs.unity3d.com/ScriptReference/Collision-contacts.html It talks about collisions, but the same general principle should apply.



Hope this helps!

0


source







All Articles