1
votes

Well I'm learning how to work with Animation parameters in Unity (I come from a Flash AS3 Background). As you can see below my goal is to get my GameObject's animation to state jump. I have the created animation parameter Booset to false, and my intention is to change it to true in the Unityscript code. The name of the GameObject's animation controller is simply controller. enter image description here

enter image description here

But the Console is telling me that they are expecting a Semicolon! As you can see there is no lack of Semicolons in my script. What is the problem here? If there is any other information that you might find helpful for solving this issue I'll be glad to post it.

1
You have really short code)) I think it must be a little bit longer var animator: Animator; animator.SetBool("Boo", true); ........ animator....not controller because it is not a Component........docs.unity3d.com/ScriptReference/Animator.htmlAlexey Shimansky
@AlexeyShimansky this didn't solve anything still getting the same error but thank you anywaysDrakeTruber
@AlexeyShimansky, I'm assuming your suggested code above is in context of my situation correct? Or is this just a an example of what I want to achieve. If so, how would I define the new variable animator? Would it be "var controller: Controller"?DrakeTruber

1 Answers

1
votes

On lines 3 and 4, you are trying to import libraries in C# style, not Javascript style.

So, instead of using you should use import:

import  UnityEngine;
import  System.Collections;
... etc.

And the error will go away. But warnings will come)) Why?

By default using UnityEngine(c#) or import UnityEngine(unityscript) and System.Collection.Generic are automatically added to the top of the script but you don't see it.

So you can remove this import, or it gives you: BCW0008: WARNING: Duplicate namespace: 'UnityEngine' and BCW0008: WARNING: Duplicate namespace: 'System.Collections'.


Also Unity3d doesn't have Controller component. But it has Animator component http://docs.unity3d.com/ScriptReference/Animator.html

In your case minimal code will be:

function Start () {
    GetComponent(Animator).SetBool("Boo", true); //(GetComponent("Animator") as Animator).SetBool("Boo", true);
}

But for global using of this component you should declare variable animator, type of Animator. And then you can use it everywhere in file.

Example (javascript tstyle):

#pragma strict

var anim : Animator;

function Start() {
    anim = GetComponent(Animator); // GetComponent("Animator");
}

function Update() {

    if (Input.GetKeyDown(KeyCode.Space))    
        anim.SetBool("Boo", true);
}

For more example click this link