- Home /
Animation error please help me!
Hi im making android FPS and when i made the PlayerAnimation.cs This error arrived: "Assets/Scripts/PlayerAnimation.cs(20,30): error CS1955: The member `UnityEngine.GameObject.animation' cannot be used as method or delegate"
PLEASE HELP ME
This is my PlayerAnimation.cs: using UnityEngine; using System.Collections;
public class PlayerAnimations : MonoBehaviour
{
public GameObject Legs;
private Joystick _LeftJoy;
// Use this for initialization
public void Start ()
{
Legs = GameObject.FindGameObjectWithTag("Legs");
_LeftJoy = GameObject.FindGameObjectWithTag("LeftJoy").GetComponent<Joystick>();
}
// Update is called once per frame
public void Update ()
{
if(_LeftJoy.position.x > 0 || _LeftJoy.position.x < 0 || _LeftJoy.position.y > 0 || _LeftJoy.position.y < 0)
{
Legs.animation("WalkForward").speed = _LeftJoy.position.y;
Legs.animation.CrossFade("WalkForward");
}
else
{
Legs.animation.CrossFade("StandIdle1");
}
}
}
I do not see any error on the specified line. Sometimes Unity goes tricky. Copy the script, delete it, recreate it and paste the script and see if it goes.
In C# doesn't the class need to equal the filename? Don't know if its related.
public class PlayerAnimations
PlayerAnimation.cs(20,30)
$$anonymous$$y only stab at this is that it doesn't like the 'Legs.' in the crossfade call. (You may need to set up your animation specifics in Start() before you make the call. It's Legacy right?)
Basically you are trying to call CrossFade as a component of the Object Legs. I think this is what makes it a delegate and CrossFade connot be used this way.
EDIT : I've speculated a lot, can someone please tell me I'm wrong and why? :D
Answer by Peter G · Aug 25, 2013 at 07:33 PM
Your problem is that you are trying to index wrong. You use square brackets to index, not ()'s.
Hence this:
Legs.animation("WalkForward").speed = _LeftJoy.position.y;
should be this:
Legs.animation["WalkForward"].speed = _LeftJoy.position.y;
Good one Peter. Any chance you can explain why this throws up as being a delegate? And why the error is on the crossfade line and not the one you've quoted? Would clear up a load of stuff.
As far as why it called the wrong line, I'm not totally sure what process it went through, but I knew it was obviously going to be within a line or two of the error. Hence I looked above it.
As to explaining why it thinks its a delegate. I can do that a little bit. The compiler sees that and it gets confused. It sees the parentheses and thinks it's a method call. And it could be. Without looking at the API, there is no way that you would know that's incorrect. Simply looking at it, it looks like animation is a function that inputs a string and outputs an object with a field named speed
.
The compiler thinks something similar to this:
class GameObject {
public Func<in string , out $$anonymous$$yClass> animation;
//Now the animation delegate takes a string and returns a class called $$anonymous$$yClass
}
class $$anonymous$$yClass {
public float speed;
}
Legs.animation("WalkForward").speed = _LeftJoy.position.y;
//Now this will compile just fine. It'd be stupid, but it would work.
That's why the compiler thinks you are trying to use it as a delegate, and obviously, animation
isn't a delegate hence it's throwing the error.
Thanks man, much appreciated. Any chance you could also look through my comment above your answer? I'd love you forever :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Marked as "Legacy" ? 3 Answers
The AnimationClip 'Running' used by the AnimationComponent 'corpse' must be marked as Legacy? 1 Answer
How To Get Current Animation Name 3 Answers
issues with animation :( 1 Answer