Hello,
Im working on a script to pick up weapons.
But I run into a few problems…
When Im in the trigger and I press “E” the dummy gets destroyed, but the weapon doesn´t gets activated.
The script is attached to the dummy.
Can someone tell me why this doesn´t work?
Thanks in advanced. ![]()
Code here:
public class PickUpWeapon : MonoBehaviour
{
public bool inTrigger = false;
void OnTriggerEnter(Collider collison)
{
inTrigger = true;
}
void OnTriggerExit(Collider collison)
{
inTrigger = false;
}
void Start()
{
GameObject.Find("Pistol").SetActive(false); //deactivates pistol
GameObject.Find("Uzi").SetActive(false); //deactivates uzi
}
void Update()
{
if (inTrigger && Input.GetKeyDown(KeyCode.E))
if (gameObject.tag == "PistolDummy") //pistoldummy = pick up pistol
Destroy(gameObject); //destroys dummy
GameObject.Find("Pistol").SetActive(true);
GameObject.Find("Uzi").SetActive(false);
if (gameObject.tag == "UziDummy") //uzidummy = pick up uzi
Destroy(gameObject); //destroys dummy
GameObject.Find("Uzi").SetActive(true);
GameObject.Find("Pistol").SetActive(false);
}
}