- Home /
Question by
KingB · Apr 04, 2017 at 05:03 AM ·
c#mousepositionmouse position
Gameobject follow mouse
void GetTurret()
{
Vector3 mouseposition = Input.mousePosition;
Vector3 mouseposition_ = Camera.main.ScreenToWorldPoint(mouseposition);
mouseposition.z -= transform.position.z;
Instantiate(object_, mouseposition_, Quaternion.identity);
transform.position = Vector3.MoveTowards(transform.position, mouseposition_, Time.deltaTime * 0.5f);
}
void Update()
{
if(Input.GetMouseButtonDown(0))
{
GetTurret();
}
}
Im trying to get the Gameobject to follow the mouse upon Getbuttondown being called, however im having no luck as of yet, any solutions?
Comment
Your answer
Follow this Question
Related Questions
Make an object move towards the mouse and then keep going 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[SOLVED] Raycast only hits one side of the box collider 1 Answer