I am about to literally go insane. Here is my problem. I have a sprite that is animating and have an empty with a box collider around is so it can interact with the world. Move.js is telling the empty to move and then setting a moving varible to 1 for use in the next script. animate.js is on the sprite and needs to acces all of the varibles in the move.js. I thought i got it right but then on the setFloat part where it is modifying the Speed var I set in the animator I got this. No appropriate version of ‘UnityEngine.Animator.SetFloat’ for the argument list ‘(String, UnityEngine.Component)’ was found. Please help. I will provide all of the information you need.
move.js
#pragma strict
public var speed : float = 2.5;
public var axisName : String = "Horizontal";
public var forward : KeyCode;
public var back : KeyCode;
public var left : KeyCode;
public var right : KeyCode;
static var moving : float = 0;
function Start () {
}
function Update () {
if (Input.GetKey(right) && !Input.GetKey(left)){
this.transform.position +=this.transform.right * speed * Time.deltaTime;
moving = 1;
Debug.Log(moving);
}
else if (Input.GetKey(left) && !Input.GetKey(right)){
this.transform.position +=this.transform.right * -1 * speed * Time.deltaTime;
moving = 1;
Debug.Log(moving);
}
else if (Input.GetKey(forward) && !Input.GetKey(back)){
this.transform.position +=this.transform.forward * speed * Time.deltaTime;
moving = 1;
Debug.Log(moving);
}
else if (Input.GetKey(back) && !Input.GetKey(forward)){
this.transform.position +=this.transform.forward * -1 * speed * Time.deltaTime;
moving = 1;
Debug.Log(moving);
}
else {
moving = 0;
}
}
animate.js
#pragma strict
public var anim : Animator;
public var axisName : String = "Horizontal";
var moving : Component;
moving = gameObject.GetComponent(move);
function Start () {
anim = gameObject.GetComponent(Animator);
}
function Update () {
anim.SetFloat("Speed", moving);
}