|
can someone break this down for me and explain this further? Use triggers. A simple sphere trigger can work wonders though. You get OnTriggerEnter/Exit calls when exiting the sphere of influence you want
Everytime i try and this script in, iget a lot of errors and i must be doing something wrong.
(comments are locked)
|
|
If you attach this kind of script to an object with a sphere collider (set to IsTrigger), every time an object which is tagged as "Player" enters the trigger, something is enabled. So far the logic is sound. However, you would have to declare your variable "enabled" at some point (beginning of the script: var enabled : boolean) and also you are missing some {} for your if statements. Try something like this: Should i add this into the update function?? If not here should i place it? And why are using the Variable called Boolean??
Feb 25 '10 at 05:27 AM
Whatee
The above code needs to be copied into an empty js script. No update function or anything else is needed. The OnTriggerEnter/OnTriggerExit are functions on their own and they get called when something enters the object's triggerzone (collider set to isTrigger). enabled is a boolean-type variable because it can only hold two values/states, either true or false (as can be seen within the functions). 'Enabled' is either set to true or false. You call such a variable a boolean.
Feb 25 '10 at 05:36 AM
Sebas
I'm getting the ERROR Node "Enabled" has not been correctly processed And points to the line enabled = true; hmmm Maybe i should explain the object and such a little more. I have a 3 piece object that rotates along its pivot looking for my player. Where it will then instantiate a projectile. I want to add a script or something causing it to only shoot when the player reaches within its range. or if possible have the turret offline until it reaches the Sphere collider trigger. Thanx
Feb 25 '10 at 06:00 AM
Whatee
my bad, enabled is no good choice for a variable name. I changed it to turretEnabled. 'enabled' already denotes the state of a component (being enabled or not) and as such is a no-go for a variable name.
Feb 25 '10 at 06:08 AM
Sebas
It fixed the error, BUT, no matter where i add this script in i cannot get any results. My enemy turret will none stop fire at me even if i'm not within its sphere collider range.
Feb 25 '10 at 06:29 AM
Whatee
(comments are locked)
|
