Hi I’m making a 2D game where the player has to move between the cities.
I created a ‘city’ prefab and added multiple city gameobject in the scene.
when the player click on a city that is next to the current city, a button has to pop up above the city that the player clicked and if u click on the button, the player moves to that city.
I used OnGUI to create the button that pops up.
However, the GUI button is being created on the top left corner instead of above the city gameobject.
How do I make the button to pop up above the gameobject?
*I am using orthographic camera projection
this is my script for OnGUI function
void OnGUI () {
if (selected) {
if (GUI.Button (new Rect (selectedCity.transform.position.x, selectedCity.transform.position.y + 10, 100, 40), "Go to this city")) {
selected = false;
}
}
}