- Home /
Question by
MaartenvB123 · Jun 10, 2015 at 08:18 PM ·
javascriptbce0017
BCE0017 Animations
im new to scripting and i dont know anything about it so can you guys help me out with this animation that has to play when i press the "fire1" button. i get this error: Assets/MeleeScipt.js(12,42): BCE0017: The best overload for the method 'UnityEngine.Component.GetComponent.()' is not compatible with the argument list '(String)'.
#pragma strict
var Damage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheKnife : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
TheKnife.GetComponent.<Animation>("Stab");
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Comment
Best Answer
Answer by Landern · Jun 10, 2015 at 08:19 PM
Line 12.
GetComponent is a generic method that takes a type in angle brackets like you did and zero parameters. You're passing the name of the animation, that is incorrect as it states in your error.
Try changing line 12 to:
TheKnife.GetComponent.<Animation>().Play("Stab");