- Home /
Move block to click
How to make this cube move to the position of the mouse and when the cube comes to a position, continues to move on?
Comment
Answer by C_R_E_A_T_R_O_R · Jul 06, 2018 at 07:55 PM
To make the cube go to the position of the mouse you can do something like this:
public Transform cube;
public Camera cam;
void Update(){
if(Input.GetButtonDown("Fire1"){
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray))
cube.position = transform.position;
}
}
Now, i dont quite get the "when the cube comes to a position, continues to move on". Are you using a navmesh agent on it?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Mecanim walk to target position 1 Answer
C# move y position of object not working 2 Answers
Distribute terrain in zones 3 Answers