Hi guys,
so, on my quest to learn unity i decided to make a 2d mini rpg.. And after doing some basic scripting and movement i decided i wanted to try making a basic melee system but it doesn't work past the Debug.Log("Step 1") even if i'm standing right next to a cube with a Enemy health Script with the "damageDeal" function in it. Why?
what did i do wrong
Here it is:
var dmg : int = 10;
var Cooldown : float = 0.5;
var Attacktimer : float = 0;
var Range : float = 20;
var dist : float;
function Update () {
Attacktimer += Time.deltaTime;
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Step 1");
// animation.Play("Attack");
Attacktimer = 0;
var collisions : Collider[] = Physics.OverlapSphere(transform.position, Range);
for (var hit : Collider in collisions) {
if (hit && hit.tag == "Enemy"){
dist = Vector3.Distance(hit.transform.position, transform.position);
Debug.Log(dist);
Debug.Log("Step 2");
if (dist <= Range)
{
hit.gameObject.SendMessage("damageDeal", dmg);
}
}
}
}
}
Sorry if this is something obvious, im new ;)
OH! and thanks in advance!!
↧