x


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);
}
more ▼

asked Dec 23 '10 at 03:54 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

Get the player, get the zone, get the distance between, if distance is less than __ (Meaning in it or next to it), do the activation (Change color of lights or whatnot, change materials?), else, make it normal...

Dec 23 '10 at 03:56 AM Justin Warner

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.

Dec 23 '10 at 04:41 AM yoyo

@yoyo No not all the time. Sometimes it works just as well, without the brackets, but sometimes it dont. :)

Dec 23 '10 at 09:04 AM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 23 '10 at 08:51 AM

Berenger gravatar image

Berenger
11k 12 19 53

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1095
x71

asked: Dec 23 '10 at 03:54 AM

Seen: 528 times

Last Updated: Dec 23 '10 at 03:54 AM