Need help with weapon pickup... - Solved

Hi. I’m new to unity and don’t know much of javascript right now :sweat_smile: . Anyways in my learning project I’m trying to make weapon pickups :slight_smile: . So I have my RocketLauncher as a child of Main Camera and a rocketlauncherpickup object which is just a mesh with a box collider (Trigger - true ) and this script attached to it :

function Start() {
var realLauncher = GameObject.Find("RocketLauncher");
realLauncher.SetActiveRecursively(false);
}


function OnTriggerEnter ( other : Collider) {
	realLauncher.SetActiveRecursively(true);
		Destroy(gameObject);
	}

When I run it it gives me: Unknown identifier: ‘realLauncher’.

I dont know what to do :? Can someone help me solve this problem?

I don’t quite remember how to do it, but you have to make a reference to the gameobject before you deactivate it or Unity cant find it anymore.

Does anyone know how to make that reference?

Well its looking for a game object called “RocketLauncher”. You are making a referance, but it is only a local variable, it means when the function goes out of scope the variable wont point to anything.

Long story short try this.

var realLauncher;
function Start() {
realLauncher = GameObject.Find("RocketLauncher");
realLauncher.SetActiveRecursively(false);
}


function OnTriggerEnter ( other : Collider) {
	realLauncher.SetActiveRecursively(true);
		Destroy(gameObject);
	}

YES! Thank you it works. :smile: