Move an object using slider (Solved)

Hi guys,

I’m trying to create a slider script for an object to move it up and down but I can’t seem to figure it out. Here’s my code…

var hSliderValue : float;
var selected : GameObject; 

function Start () 
{
hSliderValue = 0;
}

function OnGUI () {
hSliderValue  = GUI.VerticalSlider (Rect (25, 25, 100, 30),  hSliderValue, 0, 1);
}

function Update (GameObject)
{
 hSliderValue = selected.transform.position;
}

Anyone?

Ok so…

function OnGUI () 
{
hScrollbarValue = GUI.VerticalScrollbar (Rect (25, 25, 100, 130), hScrollbarValue, 1.0, 0.0, 10.0);
}

gets me the vertical scrollbar. Does anyone know how I can get this connected to an object in my scene to have it move up and down using the scrollbar?

You just need to set the Y coordinate of the target object’s position to the value returned from the scrollbar:-

var target: Transform;
    ...



function OnGUI () 
{ 
    hScrollbarValue = GUI.VerticalScrollbar (Rect (25, 25, 100, 130), hScrollbarValue, 1.0, 0.0, 10.0);

    target.position.y = hScrollBarValue;
}

Hey thanks for your response, I had gotten it solved with the help of unityanswers…

also needed

var hScrollbarValue: float;

Just in case anyone else needs this.