Script not working?
Hi, I am making a 2D Game, and I am having an error with this script:
I don't know what to do with the var error. Can someone help me please? Also notice that the word's "play" on line 23 and "time" on line 24 are red. That means they are errors too, its just that the error is hidden.
Answer by Tom01098 · May 14, 2016 at 05:41 AM
You can't use 'var' outside of functions, change that to either 'int' if you want whole numbers, or 'float' if you want decimals.
The reason Play and time are both errors is because 'animation' simply doesn't exist. You'll have to create a variable of type 'Animator' and then get the animator component before you can do what you're trying,
variables that are declared at method scope can have an implicit type var
Its just easier to use 'int', though.
Nice read, guess we all learn something on this site ;)
Answer by jkm8 · May 14, 2016 at 01:01 PM
Hi
you shouldnt use var in c#
instead use a float value like this:
public float Health = 100f;
var is perfectly valid is C# but is completely different to the UnityScript usage of var.
Check my link in the comment above.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080752im_/https://answers.unity.com/themes/thub/images/avi.jpg)