How to use Olliders in Unity?

Asked

Viewed 52 times

0

I’m creating a little basketball game, but I’m having trouble making the points system in this case (2 and 3).

Right now I’m trying with Colliders and I’m having a hard time putting the two together:


public class ponto2 : MonoBehaviour {


    void OnTriggerEnter(Collider other)
    {
        ScoringSystem.theScore += 2;
    }


public class ponto3 : MonoBehaviour {

    void OnTriggerEnter(Collider other)
    {
        ScoringSystem.theScore += 3;
    }

How do I add a Collider that when you touch it change to 3 instead of 2.

1 answer

0

There are several ways you could try to do, maybe measure the distance that was thrown from the ball to the basket or make only a circular Collider within the 2 point area, so if the player is in that Ollider the score he can make is 2 points, otherwise it is 3.

    // Player Dentro do collider de 2 pontos
    void OnTriggerEnter(Collider other)
{
    if (other.tag == "Player") other.GetComponent<SuaClasseParaoPlayer>().Pontuacao = 2;
}
// Player saiu do collider de 2 pontos
     void OnTriggerExit(Collider other)
{
    if (other.tag == "Player") other.GetComponent<SuaClasseParaoPlayer>().Pontuacao = 3;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.