- Home /
Question by
toniproto · Jan 04, 2021 at 10:18 PM ·
interactionmultiple objects
How to make a tree behave regardless of the other tree objects
thats my raycast the seccond game object is a nave mesh(dont bother) and thats a link to my scene when i cut one tree only the first falls down
void Update()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(transform.position, fwd, out hit, distance))
{
for(int i = 0; i < treeHolder.transform.childCount; i++)
{
if (hit.collider.gameObject == tree[i] && GameObject.Find("Player").GetComponent<Player>().weaponEquipped)
{
tree[i].GetComponent<Tree>().treeHealth -= GameObject.Find("Player").GetComponent<Player>().damage;
}
}
if (hit.collider.tag == "Animal" && GameObject.Find("Player").GetComponent<Player>().weaponEquipped)
{
GameObject.Find("Mitko").GetComponent<Animal>().health -= GameObject.Find("Player").GetComponent<Player>().damage;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Dragging objects like in Amnesia 2 Answers
Prevent rigidbody interaction 1 Answer
How to smoothly interact with doors? 0 Answers
Terminal Typing 0 Answers
UI mouse click prevent default / stop propagation. (Block mouse events of other scripts) 3 Answers