Hello all,
I am new with Unity.
I’m make the Lerpz tutorial and now I like improve this.
I’m construct a “event” it consist a sphere colider and a 6 gameObjects(Copper the enemy robot).
I put the enemis in the map and deactivate this and I wanna activate when player colider with sphere.
I use this code line on triggered sphere collider: GameObject.Find(“CopperTrap1”).active = true;
But this make a NullReferenceException… Any idea for activate GameObject previusly deactivated in the Unity Interface?
Thz! and Have great day!
Sorry for me english.
Welcome aboard.
I do not believe that you can “Find” a deactivated object. What you can do is associate it with an object. Say you have a variable CopperTrap1 : GameObject; You drag the trap to the object and then in the code active will be available… even if it was previously inactive.
Now, I suspect that just finding an object is not your intent, however, what you would like to know is if the player comes within a certain distance of the trap, so that it can explode, or whatever.
To do this, change the collider to a sphere (or cube depending on what best fits your application) turn it into a trigger then use the OnTriggerEnter event. Check to see if whatever entered the area is a player, if so… Explode.
Find will work if you use SetActiveRecursively(true/false) instead of using the active property.
Thz all for help!
This works normally, but how I can compare the gameObject Player with other : Collider?
Thz and have good day.
other.gameObject==gameObject