Camera go to point on click GUI

Hi
I need to create a few buttons that when clicked, will make the camera or first person walker go to location’s on my terrain…
Not a programmer, but working through a project and need help…

Thanks
Dex

You can mark the locations by adding an empty GameObject at every appropriate position. In the GUI script, declare an array of Transform at the start:-

var markers: Transform[];

The markers array should now be visible in the inspector. Set its size to the number of markers and then drag the marker objects onto consecutive array elements (ie, each element links to its own marker).

A neat way to handle the GUI is to use a SelectionGrid which will allow you to create a clickable button for each element of the array. You may want to give the buttons descriptive names or just use numbers, depending on how you want the GUI to look:-

var markerNames: String[]; // One element for each marker.
var currMarker: int;
var gridRect: Rect;

function OnGUI() {
   currMarker = GUI.SelectionGrid(gridRect, currMarker, markerNames, 1);
}

Then, in the Update function, jump to the selected marker:-

function Update() {
   player.transform.position = markers[currMarker].position;
}

You’ll most likely want to adapt this for what you are doing, but it should give you a start.

Hey

Many, many thanks for this start. The more i do this stuff the more its starting to make sense. So with help like this, its invaluable to me.
I will let you know how i get on.

Thanks
Dex

This works great,
however i cant figure out how to get the camera to move again once it goes to the target objects. It just freezes or locks to that position.
I tried to use an if condition but it just wont work…Any help please

Thanks for getting me this far
Dec

How is the camera controlled? Can you post the code you are using? (Or if you are using a publicly available script, then please post a link to it.)

A friend of mine worked this out for me. Daniel Monroe www.LogisticWin.com
Thanks Daniel!

var marker1: Transform;
var marker2: Transform;
var marker3: Transform;

function OnGUI() {

if (GUI.Button(Rect(0, 0, 300, 50), “1”)){
transform.position = marker1.position;
}
if (GUI.Button(Rect(0, 55, 300, 50), “2”)){
transform.position = marker2.position;
}
if (GUI.Button(Rect(0, 110, 300, 50), “3”)){
transform.position = marker3.position;
}

}

And many thanks to you as well
Dex