Question by
Dylanpolis · Dec 03, 2016 at 10:12 AM ·
javascriptscripting problem
I am trying to enable multiple scripts from different objects that have the same tag by using javascript. I keep getting a NullReferenceException: Object reference not set to an instance of an object LightPickup.js:37. What am i doing wrong?
var varGameObject = gameObject.FindGameObjectsWithTag("Flashlight");
if(Input.GetKeyDown("e"))
{
for (var obj : GameObject in varGameObject) {
obj.GetComponent.<FlashLight1>().enabled = true;
obj.GetComponent.<FlashLight2>().enabled = true;
}
Comment
in your case, every gameobject with the Tag "Flashlight" must have both scripts, FlashLight1 and FlashLight2. If not that's why you're getting these errors. It's just a few lines so you should be able to debug it with either break points or putting Debug.Log into the loop to see which it failed last on.
Could you explain to me as if this were my first time ever hearing that. Im sorry im just very new at coding.
Your answer
