x


Position slider?

Many racing games will show the player's position relative to the level on a map, is there anyway to do this using unity's built in horizontal slider GUI element? So one end represents one position(I only want to measure the z axis), and the other end represents another, and the buttons position shows the player how close they are to the end of the level (the level is one way only, so perhaps the race track comparison was a bit off). Thanks

EDIT: I tried do to what yoyo suggested, but I get the error

"Assets/NewBehaviourScript.js(6,27): BCE0023: No appropriate version of 'UnityEngine.GUILayout.HorizontalSlider' for the argument list '(float, UnityEngine.Transform, UnityEngine.Transform)' was found."

How do I convert the player's position to a value?

var player : Transform;
var z_start: Transform;
var z_end  : Transform;

function OnGUI (){
GUILayout.HorizontalSlider(player.transform.position.z, z_start, z_end);
}
more ▼

asked Jan 10 '11 at 02:42 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

z_start.position.z and z_end.position.z

Jan 10 '11 at 06:04 AM Mike 3
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You mean like this?

GUILayout.HorizontalSlider(player.transform.position.z, z_start, z_end);

Since you do nothing with the return value (though letting the user drag themselves through the level with the slider might be an interesting cheat :-), the slider thumb will be effectively disabled from user control.

more ▼

answered Jan 10 '11 at 04:26 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3675
x884
x103

asked: Jan 10 '11 at 02:42 AM

Seen: 1304 times

Last Updated: Jan 10 '11 at 05:43 AM