Hi guys, i want to instantiate a tower at my cursor’s location when i click the tower’s button in the menu. My problem is that when i do a debug.log on my cursor’s position, it looks like 400,0,40 ( arround i dont remember the exact number). My point is , the tower does get instantiated but at a very far position… How can i solve this to get the “real” cursor position ? Thanks again guys !
So here’s my code to do that
void Update ()
{
mousePos.x = Input.mousePosition.x;
mousePos.y = floorYpos;
mousePos.z = Input.mousePosition.z;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit, Mathf.Infinity))
{
if (hit.transform.tag == "Guardian")
{
if(Input.GetMouseButtonDown(0))
{
checkIfClicked = true; // pops the menu over my "guardian"
}
}
}
if (summoninMonkey == true)
{
Instantiate(monkey,mousePos,transform.rotation);
Debug.Log("its working");
summoninMonkey = false;
}
}
void OnGUI ()
{
if(checkIfClicked == true)
{
GUILayout.BeginArea(new Rect(350,25,120,120));
if (GUILayout.Button("Summon Monkey", GUILayout.Width(120), GUILayout.Height(30)))
{
summoninMonkey = true;
Debug.Log("going to change cursor for tower");
}
if (GUILayout.Button("Close Menu"))
{
Debug.Log("Closing menu");
checkIfClicked = false;
}
GUILayout.EndArea();
}
}