- Home /
The question is answered, right answer was accepted
position.Set vs. position = new Vector3()
Why does vector = new Vector3(..)
work, but vector.Set(..)
does not? The Documentation of Vector3.Set
does not list any special cases.
Detail:
I want a gameobject to follow the cursor. Therefore I call in the Update method the function stickItemToCursor()
that will achieve this.
This works:
_itemInUse.transform.position = new Vector3(mousePosition.x, mousePosition.y, 1.0F);
... but Vector3.Set(..)
does not to work (the position does not change):
_itemInUse.transform.position = new Vector3(mousePosition.x, mousePosition.y, 1.0F);
Edit:
Solution: transform.position
is a getter - so it returns a copy of the Vector3
where the position is stored. If you call Set
on gameObject.transform.position
only the copy will be edited.
Discussed here: http://answers.unity3d.com/questions/225729/gameobject-positionset-not-working.html
Follow this Question
Related Questions
I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers
Unity Ui. Why constant pixel size option in Canvas Scaler don't work with mouse? 1 Answer
How to Check if any object is at an specific Vector3? 1 Answer
Help with this script? Keeps moving my objects around in run-time? 0 Answers
How to check if mouse position is near position of a Vector3 on screen ? 0 Answers