- Home /
Object activation?
Hello. I want to make a king of the hill type area in my scene. When the player is in it, another object is active and when the player is not in it, said object is not active. I have tried to do this, I am not getting any errors, but it is not working, what is wrong with my script(it is attached to the hill area)? Thanks
var Weapon : GameObject;
function OnTriggerEnter (other : Collider) { if (other.gameObject.CompareTag ("Player")) Weapon. active = true ; Destroy(gameObject,10); }
Get the player, get the zone, get the distance between, if distance is less than __ ($$anonymous$$eaning in it or next to it), do the activation (Change color of lights or whatnot, change materials?), else, make it normal...
I'm not a Java guy, but don't you need curly braces {} around the two statements following the "if"? Looks like the Destroy may run every time.
@yoyo No not all the time. Sometimes it works just as well, without the brackets, but sometimes it dont. :)
Answer by Berenger · Dec 23, 2010 at 08:51 AM
Does your hill area your script is attached to have any collider with isTrigger true ?
It seems odd to destroy the hill once you enter it though, you sure about that ?
And yoyo is right, you need {} or else anything with a collider entering your hill area will trigger the destruction.
Your answer
Follow this Question
Related Questions
How to activate another Object with java script? 4 Answers
GameObject.find and positioning 1 Answer
SetActive won't work 3 Answers
Restricting GameObject Rotation 1 Answer
Object Follower 1 Answer