How to initate attack animation on keypress with a variable? (bcos animation.Play is outdated)
Herro. I am trying to play an attack animation when the button "Fire1"/Mouse 1 is clicked but the code is shown to be outdated on Unity 5. (PlayerSword is a variable set to Transform). What would I use to replace variablename.animation.Play("attacksword") and get my sword to animate?
Error msg: Assets/Player/MeleeSystem.js(12,25): BCE0144: 'UnityEngine.Component.animation' is obsolete. Property animation has been deprecated. Use GetComponent() instead. (UnityUpgradable)
Particular Section:
 if (Input.GetButtonDown("Fire1"))
     {
         PlayerSword.animation.Play("attacksword")
 
               }
Full Script:
 #pragma strict
 
 var TheDamage : int = 50;
 var Distance : float;
 var MaxDistance : float = 1.5;
 var PlayerSword : Transform;
 
 function Update() 
 {
     if (Input.GetButtonDown("Fire1"))
     {
         PlayerSword.animation.Play("attacksword")
         var hit : RaycastHit;
         if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if (Distance < MaxDistance)
             {
                 hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
             }
         }
     }
 }
 
 
              Your answer
 
             Follow this Question
Related Questions
How to i go about playing a animation when Left mouse is clicked? C# 0 Answers
Crossfading happens too fast 2 Answers
Animation timeline 1 Answer
3d animation breaking 0 Answers
How do I make an animation activate by clicking the mouse button in unity5? 0 Answers