Z
Z
Zimaell2020-07-26 18:09:19
Unity
Zimaell, 2020-07-26 18:09:19

How to make prefab mouse tracking?

An example is this - I click to build a tree, for example, when I drive around the stage, where I drive this tree appears (prefab), they say where to put it, something like

public void MouseEnter(){
  Instantiate(tree, transform.position, transform.rotation);
  }
public void MouseLeave(){
  Destroy(tree);
  }

That's not how it works, more precisely, a tree appears there but does not disappear ...
Tell me how to do this?
And if at the same time the prefab is made transparent, then it would be what you need ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zZaKko, 2020-07-27
@zZaKko

Your tree is the prefab of the object you are spawning. How do you for-destroy-esh? You have to assign your Instantiate to a GameObject variable and that variable and destroy.

GameObject new_tree;
public void MouseEnter(){
 new_tree = Instantiate(tree, transform.position, transform.rotation);
  }
public void MouseLeave(){
  Destroy(new_tree);
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question