- Home /
Question by
ChocopopGames · Jan 09, 2014 at 02:27 AM ·
javascriptaienemydamagehealth
The enemy don´t lose health, but why???
#pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
animation.Play("Attack");
}
// if (TheMace.animation.isPlaying == false)
// {
// TheMace.animation.CrossFade("Idle");
// }
//
// if (Input.GetKey (KeyCode.LeftShift))
// {
// TheMace.animation.CrossFade("Sprint");
// }
//
// if (Input.GetKeyUp(KeyCode.LeftShift))
// {
// TheMace.animation.CrossFade("Idle");
// }
}
function AttackDammage ()
{
//Attack function
var hit : RaycastHit;
if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
Comment
Answer by robertbu · Jan 09, 2014 at 02:31 AM
'AttackDamage()' is never called. Likely you should have this in Update():
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
animation.Play("Attack");
AttackDamage();
}
}
Your answer
Follow this Question
Related Questions
how can i do a headshot with a rigidbody bullet? 1 Answer
Deal damage on collision 2 Answers
Enemy detection in the light(Javascript) 1 Answer
Enemy AI Problem: Dancing? 1 Answer