This question was
closed Sep 05, 2016 at 05:09 PM by
ashawedoosra for the following reason:
The question is answered, right answer was accepted
Question by
ashawedoosra · Sep 03, 2016 at 01:31 PM ·
animationerroranimator
Getting this error:BCE0020: An instance of type 'UnityEngine.Animation' is required to access non static member 'Play'.
this is my first script:
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
Animation.Play("attack");
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);
}
}
}
}
and this is the second one: #pragma strict
var Health = 100;
function Update()
{
if(Health<=0)
{
Dead();
}
}
function ApplyDamage(TheDamage : int)
{
Health -= TheDamage;
}
function Dead()
{
Destroy (gameObject);
}
Comment
Best Answer
Answer by tanoshimi · Sep 03, 2016 at 01:32 PM
Animation.Play("attack");
should be:
GetComponent<Animation>().Play("attack");
Follow this Question
Related Questions
Unity Editor Animator Not Set To Instance Of Object 0 Answers
Apk on android does not start. Reason: Animator | Не запускается Apk на андройд. Причина: Animator 0 Answers
Error no animation attach to bear 0 Answers
I want to animate with SetTrigger? 0 Answers
Unity, Mechanim And Mixamo 3D Animation: NullReferenceException. 0 Answers