Hi, idk how is this working, but in my game LAZERS, you need to be next to a weapon to take it by pressing a button
Everything is working fine in the editor and in build too, when V-Sync is enabled
If not, the collision is detected 1/4 time, that’s very anoying…
Here is how my script is detecting the gun’s trigger :
void OnTriggerStay2D(Collider2D collider)
{
if (collider.gameObject.tag == "Weapon")
{
if (gamemanager.keyboard && playerNumber == 4) {
if (Input.GetKeyDown(gamemanager.take) && cooldown <= 0 && !haveWeapon)
{
gamemanager.vibration[playerNumber - 1] += 0.2f;
Weapon weapony = collider.gameObject.GetComponent<Weapon>();
if (weapony != null)
if (weapony.playerEquiped != null)
{
weapony.playerEquiped.haveWeapon = false;
weapony.playerEquiped.weapon = null;
}
weapon = collider.gameObject;
weapon.transform.parent = gameObject.transform;
weapon.GetComponent<Weapon>().playerEquiped = this;
weapon.GetComponent<Weapon>().equiped = true;
haveWeapon = true;
takeWeaponSound.pitch = takeWeaponSound.pitch = Random.Range(1f, 1.2f);
takeWeaponSound.Play();
if (weapon.GetComponent<Weapon>().part != null) weapon.GetComponent<Weapon>().part.gameObject.SetActive(false);
cooldown = 0.1f;
}
}
}
}