I’m prety new to unity and im trying to figure out how to make this script attached to objects in the trigger zone only work when the player enters the trigger zone…any ideas? Thank you.
//attach this script to your trigger
var Player : GameObject;
var Script : theScript;
function OnTriggerEnter(other : Collider) //Check if something has entered the trigger ( and declares this object in "other" )
{
if(other.collider.tag == Player.tag) //Checks if the Player is inside the trigger
{
Script = GetComponent(theScript);
Script.enabled = true; //enables theScript.
}
}
You have to change
“theScript” to the name of the script you want to enable.
e. g. when you named your script “Toaster” it would be
var Scipt : Toaster;
Script = GetComponent(Toaster);
you can disable the script again if you copy-paste the script and change
function OnTriggerEnter(other : Collider)
to
function OnTriggerExit(other : Collider)
and
Script.enabled = true; //enables theScript.
to
Script.enabled =false; //this time it will disable the script
I hope i could help you
I'm using this script to fire up a random number generator (so when player enters a trigger zone, it will create a random number 0 - 17) but I keep getting: "Assets/Scripts/Trigger.js(4,14): BCE0018: The name 'RandomNumberGen' does not denote a valid type ('not found'). Did you mean 'UnityEngine.RuntimeAnimatorController'? Could this be because my Trigger script is JavaScript, and my RandomNumberGen script is C# ?
I'm using this script to fire up a random number generator (so when player enters a trigger zone, it will create a random number 0 - 17) but I keep getting: "Assets/Scripts/Trigger.js(4,14): BCE0018: The name 'RandomNumberGen' does not denote a valid type ('not found'). Did you mean 'UnityEngine.RuntimeAnimatorController'? Could this be because my Trigger script is JavaScript, and my RandomNumberGen script is C# ?
– christian24689000