Why does this script not work? (JavaScript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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); } }

1st Mar 2018, 4:35 PM
Pit Lempens
Pit Lempens - avatar
7 Answers
+ 14
line 1 : var Healph = int = 100 ; or var Health , int = 100 ; ? and line 2 var CubeEnemy , GameObject ; 🤔
1st Mar 2018, 4:47 PM
Maxımee
Maxımee - avatar
+ 13
oh okay 🙂 sorry :/
1st Mar 2018, 4:50 PM
Maxımee
Maxımee - avatar
+ 6
This is UnityScript and not Javascript. UnityScript is used to run Unity apps. The normal JS is used for webpages.
1st Mar 2018, 5:05 PM
Gami
Gami - avatar
+ 4
that is NOT javascript
1st Mar 2018, 4:38 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 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.
1st Mar 2018, 4:49 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 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.
1st Mar 2018, 4:47 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 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.
1st Mar 2018, 4:51 PM
Fata1 Err0r
Fata1 Err0r - avatar