Question by
ChrisElmore11 · Mar 14, 2016 at 01:57 PM ·
c#animationerrorfloatparameters
The name animator does not exist in the current context... Help?
Ok, so I have this code that's setup to change the parameter in my animator controller from 0 to 1 when the W key is pushed down. This is the code I have:
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.W))
{
animator.SetFloat ("Forward", 1);
}
}
}
But the problem is that it has errors that say that the keyword animator isn't recognized... Here's an image to show exactly what I mean.
screen-shot-2016-03-12-at-61642-pm.png
(288.0 kB)
Comment
Answer by Zoogyburger · Mar 14, 2016 at 05:07 PM
In your script add this line before the void Start:
Animator animator;