Ive been messing around with this part of code to make this work with a collision of my weapon, instead of raycast because my game is thirdperson, any ideas how I can change this script? Thank you!
#pragma strict
var rayLength = 10;
private var treeScript : TreeController;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Tree")
{
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent(TreeController);
if(Input.GetButtonDown("Fire1") && playerAnim.canSwing == true)
{
treeScript.treeHealth -= 1;
}
}
}
}