object detects collision of a script when not actually colliding, cause another object with same scr

Options
Faqui
Faqui

I'm pretty new with Photon, been following BackThorProd tutorials and got to this point where all the players have the same script attached to them, then when I try to FindObjectOfType to refer to one player, it detects all other scripts attached to the other players, even if they're not colliding with anything. Here's my code:


void Start()
    {
        // missileLaunchSFX = GetComponent<AudioSource>();
        buttonSFX = GetComponent<AudioSource>();
        myAnimator = GetComponent<Animator>();
        buttonCollider = GetComponent<BoxCollider2D>();
        view = GetComponent<PhotonView>();
    }

    public void OnTriggerEnter2D(Collider2D other) 
    {
        if(other.gameObject.tag == "Player" && FindObjectOfType<Movement>().rb2D.velocity.y < 0.1 && !missileHasLaunched)
        {
            // missileLaunchSFX.Play();
            buttonSFX.Play();
            myAnimator.SetBool("isPressed", true);
            missileHasLaunched = true;
            SpawnMissile();
            Destroy(buttonCollider);
        }
    }

Answers

  • Tobias
    Options

    That is more a Unity question. FindObjectOfType<Movement>() is meant to do that!

    Instead, you may want to find a component on both objects that collided?