I added a tree controller script to make tree die and spawn logs but now it dies and spawn wood even if I attack something other than tree . It dies if I just swing my mace even though iam not aiming the tree . why this happens ? and also it would be better if someone tell me how to make tree fall and then destroy the tree not just destroy when I attack . I want it to fall down and then spawn woods. here is the TreeController script
#pragma strict
var treeHealth :int =5;
var logs :Transform;
var tree :GameObject;
var speed :int =-8;
function Start ()
{
tree = this.gameObject;
GetComponent.().isKinematic = true;
}
function Update()
{
{
if(treeHealth ← 0)
GetComponent.().isKinematic = false;
GetComponent.().AddForce( transform.forward * speed);
DestroyTree ();
}
}
function DestroyTree ()
{
yield WaitForSeconds(7);
Destroy(tree);
var position : Vector3 = Vector3(Random.Range(-1.0, 1.0), 0 ,Random.Range(-1.0 , 1.0));
Instantiate( logs, tree.transform.position + Vector3 (0,0,0) + position, Quaternion.identity);
Instantiate( logs, tree.transform.position + Vector3 (2,2,0) + position , Quaternion.identity);
Instantiate( logs, tree.transform. position+ Vector3 (5,5,0) + position , Quaternion.identity);
}
and sorry for not using tags cause got the problem