I Have scripts that player send message dammage to enemies using raycast hit. but every player hit the enemies the functions didnt work. here the scripts
* MeleeScript.js (player script assigned on weapon object with mecanim, sending dammage message to enemies)
----------------------------------------
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;
var theAnimator : Animator;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
theAnimator.SetBool("Hit01", true);
}
if(Input.GetButtonUp("Fire1"))
{
theAnimator.SetBool("Hit01", false);
}
if(Input.GetButtonDown("Fire2"))
{
theAnimator.SetBool("Hit02", true);
}
if(Input.GetButtonUp("Fire2"))
{
theAnimator.SetBool("Hit02", false);
}
}
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);
}
}
}
* EnemyHealth.js (default health of enemies, its reciever dammage from player)
----------------------------------------------
var Health = 100;
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Destroy (gameObject);
}
Even the distance between player and enemy very close, its still no happens
![alt text][1]
[1]: /storage/temp/20198-11.jpg
How to resolve the problem ? Thanks before.
↧