- Home /
How to set the mouse x and/or z position as a variable
I just wanted to ask how to get the x and z position of my mouse cursor. I need for my rts-style game. I have a button and when the player presses it, the game initiates my house prefab. But i find myself unable to create it at my mouse coordinates. I only can create it at some defined points ( 0, 1, 0).
My code looks as follows for the moment: var house : Transform;
var z = RaycastHit.point.x;
var x = RaycastHit.point.z;
function OnGUI () {
if (GUI.Button (Rect (10,10,100,30), "Domek")) {
Instantiate (house, Vector3( x,1, z), Quaternion.identity);
}
}
Answer by Julien-Lynge · Feb 15, 2012 at 04:54 PM
Is there code you haven't posted here? What you have posted doesn't make sense, and shouldn't work. 'point' isn't a static function, so RaycastHit.point makes no sense.
Use the UnityAnswers search function - your question has been answered many times before.
http://answers.unity3d.com/search.html?redirect=search%2Fsearch&q=instantiate+at+mouse+position