- Home /
No custom scripts will work.*Using US.*
US = UnityScript.
I am a newbie, and made a basic script.
function OnTriggerEnter() { Debug.log("Hiya"); }
You know, BASIC. And when I play, it doesn't show an error, but it DOESN'T print in the output. Now I tried some different things, like.
var health = 10;
function OnTriggerEnter(){ health - 1; Debug.log("You lost some health dear soul."); }
The 2nd script, it made a variable named health, put it to 10, but it errors out and I can't even play the game. How come no scripts are working? yet imported ones DO work. I use MonoDevelop.
The Documentation says, one of the colliders needs a rigidbody attached, did you make sure that this is the case?
Answer by MichaelTaylor3d · Nov 01, 2012 at 08:49 PM
OnTriggerEnter is triggered when a collider that is flagged as a trigger enters the collider of your script. If you want your log message to run when you hit play. Try putting it in function Start()
function Start()
{
Debug.Log("Hiya");
}
Wait, what do you mean about the OnTriggerEnter? And I am guessing 'Start' means as soon as the game starts playing?
that is correct Awake() runs as soon as the script is instantiated. Start() runs as soon as the script runs. OnTriggerEnter() runs when a trigger collider enters the collider of a gameobject your script is attached to.
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Start.html
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Awake.html
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
PS dont forget to accept any correct answers people give you.
Your answer
Follow this Question
Related Questions
Question on UnityScript and C# 1 Answer
A node in a childnode? 1 Answer
Whats a good place to learn UnityScript? 1 Answer
UnityScript auto-format? 0 Answers