A different approach

does this also work ? i went for another approach wanted to know is it just as effective or not ?

public class PrimaryTrigger : MonoBehaviour {
Collider stored;
void OnTriggerEnter(Collider collider)
{
stored = collider;

}
public bool ExpectCollider(Collider c)
{
    if (stored == c)
        return true;
    else
    {
        return false;
    }
}

public class SecondaryTrigger : MonoBehaviour {
PrimaryTrigger pT;
public int points = 1;

private void OnTriggerEnter(Collider collider)
{
    pT = GetComponentInParent<PrimaryTrigger>();
    if (pT.ExpectCollider(collider))
    {
        ScoreKeeper sK = FindObjectOfType<ScoreKeeper>();
        sK.IncrementScore(points);
    }

}

}

I think this also work too because you are just asking if the collider of the primary trigger is the same of the collider in the second trigger then increment your score.

I think yes.

Privacy & Terms