- Home /
Question by
Eowyn27 · Feb 04, 2014 at 02:54 PM ·
cameragameobjectgui-buttonfindgameobjectwithtag
How do I make a Gui button appear after the camera moves to a specific view?
That is, if I had my camera move to specific view with a game object tagged "block", I want a gui button that says "back" to appear on the view. This gui button would only appear after the camera moves to show a game object tagged block on the scene.
I started to hard code everything as this is the only way I know how but this is a horrible way to write it and I'm not sure how to proceed to make it better.
if (GameObject.FindGameObjectWithTag("Block") && mainCam.transform.position == new Vector3(18, 1, -72)) {
if (GUI.Button (new Rect (5,Screen.height-40,170,30), "Back")) {
print ("You clicked the button!");
mainCam.transform.position= new Vector3(0, 1, -10);
Camera.main.orthographicSize = 10f;
}
}
However, I would have to do this for every block on the scene (as the game objects tagged with block are numerous and on different coordinates).
Is there a way I can incorporate GameObject.FindGameObjectWithTag("Block") and the varying camera movements without having to write the above script e.g. 10 times if I have 10 blocks?
Comment