- Home /
var TheCollision : Collision
function OnCollisionEnter(TheCollision : Collision){
if(TheCollision.gameObject.name == "Floor"){ Debug.Log("Hit The Floor"); } else if(TheCollision.gameObject.name == "wall"){ Debug.Log("Hit The Wall"); } }
This is a simple Collision Javascript. There is one thing i don't get since switching Game languages.
In my previous Language it would be.
var x , y; x = mouse_xx y = mouse_yy
That would store xx and yy variable in the current position of the object.
What i do get is this var Speed : int;
i'ts almost the same, but you can save it as a float or boolean to.
But i don't get is this
function OnCollisionEnter(TheCollision : Collision)
How does TheCollision variable(if it is) play a part in the Collision ? That all i don't get about UnityScript!
Thanks ~Wentzel
Answer by deadfire56 · Oct 30, 2011 at 08:25 PM
The OnCollisionEnter is a method that is called when there is a collision. The information from the collision is stored in the variable TheCollision which you can use to tell what it hit.
UnityScript is the same as JavaScript except that it has it's own predefined classes and methods that make making a game easier.
UnityScript is barely like Javascript, except for some superficial syntax. It's a lot more like ActionScript 3 or JScript.NET
.
Your answer
Follow this Question
Related Questions
Display variables in GUIText? 1 Answer
One of my scripts can't find the variable from this script 1 Answer
How do you change a variable in a script, that is on an object instantiated from a prefab? 0 Answers
Import Variables from another active script 1 Answer
How to make a variable equal to Random.Range Result 1 Answer