- Home /
Snap object in game using script?
Hello
I am wondering how would you snap a game object in game through script like you do when you hold Ctrl and move an object in the editor?
Answer by Aydan · Nov 30, 2011 at 02:08 AM
Its ok I found something that works
function Start () {
var xPos = transform.position.x;
var yPos = transform.position.y;
var zPos = transform.position.z;
xPos = Mathf.Round(xPos * 1) / 1;
yPos = Mathf.Round(yPos * 1) / 1;
zPos = Mathf.Round(zPos * 1) / 1;
transform.position.x = xPos;
transform.position.y = yPos;
transform.position.z = zPos;
}
Answer by zmar0519 · Nov 30, 2011 at 01:48 AM
You would need to set up a grid system that cycles through an array of Vector3's using three for loops. then, you just determine if the distance between the current point and the object is greater than that of another point, and move it there.
Your answer
Follow this Question
Related Questions
how can I display a variable as a GUIText 5 Answers
Destroy all GameObjects EXCEPT some... 2 Answers
Errors when trying to enable script on gameobject. 0 Answers
enable scripts/ components on other gameobjects for a different gameobject? 1 Answer
Hide/Show a game object and activate/deactivate a script of another game object with one script 1 Answer