I have a crate that drops into my world and I want to to stay there until the player comes along and trigger the trigger collider. The problem is my crate reacts to anything it touches instead of only the player.
public class Crate : MonoBehaviour {
// Variables
Player player;
GunController gunController;
void Start() {
player = FindObjectOfType<Player>();
gunController = player.GetComponent<GunController>();
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
gunController.EquipGun(gunController.allGuns[Random.Range(0, 4)]);
}
Destroy(gameObject);
}
}