Question by
xxx_ProDeveloper_xxx · May 11, 2016 at 01:15 AM ·
animationcharacter
Hey guys I am getting an error that says " 'Play' is not a member of 'UnityEngine.Component'"
I don't understand what's wrong and I am still a bit new to js. I am doing an animation and this error keeps coming up, I can't find the error hopefully you guys can help. The error is at line 31 and it's with the swinging animation.
#pragma strict
private var hasAxe : boolean = false;
private var canSwing : boolean = true;
private var isSwinging : boolean = false;
private var controller : CharacterController;
private var playerGUI : PlayerGUI;
var swingTimer : float = 1;
function Start()
{
hasAxe = true;
controller = GameObject.Find("First Person Controller").GetComponent(CharacterController);
playerGUI = GameObject.Find("First Person Controller").GetComponent(PlayerGUI);
}
function Update()
{
//AxeSwinging
if(hasAxe == true && canSwing == true)
{
if(Input.GetMouseButton(0));
{
//ReduceStamina
playerGUI.staminaBarDisplay -= 0.1;
//Swinging Animations
animation.Play("Swing");
animation["Swing"].speed = 2;
isSwinging = true;
canSwing = false;
}
}
if(canSwing == false);
{
swingTimer -= Time.deltaTime;
}
if(swingTimer <= 0)
{
swingTimer = 1;
canSwing = true;
isSwinging = false;
}
}
Comment
Answer by incorrect · May 11, 2016 at 01:24 AM
animation is deprecated. Use GetComponent() to get reference to Animation component.