+ 2
Why does this script not work? (JavaScript)
I'm working in Unity (MonoDevelop) and I'm trying to make it so that when I enter a certain area it gives a cube damage so that it will disappear within two times of entering the area. Here's the script: var Health : int = 100; var CubeEnemy : GameObject; function OnTriggerEnter (Collider other) { if (other.CompareTag ("Player")) { Health -= 50; } if (Health <= 0) { CubeEnemy.SetActive (false); } else { CubeEnemy.SetActive (true); } }
7 Answers
+ 14
line 1 :
var Healph = int = 100 ;
or var Health , int = 100 ; ?
and line 2
var CubeEnemy , GameObject ;
đ€
+ 13
oh okay đ sorry :/
+ 6
This is UnityScript and not Javascript. UnityScript is used to run Unity apps. The normal JS is used for webpages.
+ 4
that is NOT javascript
+ 4
@Maxime
Technically, it's UnityScript, which isn't JavaScript. However, most of the community calls it JavaScript, and I've even seen Unity Dev's refer to it as such.
+ 3
@Pit
What exactly happens when you do this? Did you place the script on the object yet? Any errors?
Also, just as a side note, Unity stopped supporting UnityScript. Obviously you can still use it, but it's advisable to switch over to C# for the scripting. It's much more efficient and you'll also find a lot more support/resources for it in regards to Unity.
+ 3
lol No need to apologize. I usually refer to it as JavaScript as well because even in their official documentation they referred to it as JavaScript when I was originally learning Unity.