Hey all,
Here is what I’m trying to do.
I’m attempting to use a Horizontal slider to control a plane’s y transform variable
here is what I have so far.
var hSliderValue : float = 0.0;
var hv: Vector3;
var horizdisplaytext: String;
var crazy: Transform;
var plane: GameObject;
function Start(){
crazy = gameObject.GetComponet(Transform);
crazy = gameObject.transform;
}
function Update(){
hv = Vector3.up;
var horizdisplay: float=hv.magnitude;
horizdisplaytext = horizdisplay.ToString();
}
function OnGUI () {
hSliderValue = GUILayout.HorizontalSlider (hSliderValue, 0.0, 10.0);
GUILayout.Label("This text makes just space");
GUI.Box(Rect(Screen.width - 110,Screen.height *0.8,100,50), hSliderValue + " TEST");
}
The code isn’t working as right now im having trouble linking the slider with the transform variable
any help would be great. THANKS!
BTW. the plane is taged as Plane
1 Answer
1
Here is a few modifications to your code so that the slider will move a plane up and down. Note a plane is one-sided, so if you lift it so that you are looking at the bottom, the plane will disappear. I’ve set the value range from -10 to 10:
#pragma strict
var hSliderValue : float = 0.0;
var hv: Vector3;
var horizdisplaytext: String;
private var crazy: Transform;
private var plane: GameObject;
private var startY : float;
function Start(){
//crazy = gameObject.GetComponet(Transform);
crazy = gameObject.transform;
plane = GameObject.Find("Plane");
startY = plane.transform.position.y;
}
function Update(){
hv = Vector3.up;
var horizdisplay: float=hv.magnitude;
horizdisplaytext = horizdisplay.ToString();
}
function OnGUI () {
hSliderValue = GUILayout.HorizontalSlider (hSliderValue, -10.0, 10.0);
plane.transform.position.y = startY + hSliderValue;
GUILayout.Label("This text makes just space");
GUI.Box(Rect(Screen.width - 110,Screen.height *0.8,100,50), hSliderValue + " TEST");
}