GUI Slider and Movement?

Hello everyone,

I’m trying to fix this script, I want to move one object to another point.
the problem is that the movement is continuous and ends without control. I have tested a lot of examples but without success.

I want to control the movement exactly as the movement of my GUI Slider. I’m using a Static Variable from my GUI.Slider script to control the script applied to the object.

Please any advice is more than welcome!

Please see my scripts.

Script Object

var start : Transform;
var end : Transform;

function Update () {
function move(){ 
amtToMove = buttonsGUI. vSliderValue  * Time.deltaTime;
transform.position = Vector3.Lerp(start.position, end.position, Time.time);

Script GUI Slider

static var triggerGo : int;
static var vSliderValue : float = 0.0;

var vthumbStyle : GUIStyle;
var vsliderStyle : GUIStyle;
var Skin_power : GUISkin; 
var beep : AudioClip;

function OnGUI (){

 	vSliderValue = GUI.VerticalSlider (Rect (887.5, 10, 50, 203), vSliderValue, -1500.0, -100.0,vsliderStyle,vthumbStyle); = Skin_power;
	if (GUI.Button(Rect(870,227,80,56),"")){
	triggerGo = (triggerGo + 1) % 2;

@script RequireComponent(AudioSource)

Since you say, “control the movement exactly,” here is some code that moves them together. The fraction calculation looks a bit messy because of your unusual values for the bottom and top of the slider. The line calculates the fraction of the way from the bottom to the top the current value places the slider. I’ve left minus signs in so you can see how your original values are used. Untested:

function Update() {
    var fraction : float = (vSliderValue - (-1500.0)) / ((-100.0 - (-1500.0));
    transform.position = Vector3.Lerp(start.position, end.position, fraction);

I see several problems, actually.

First, while it looks like amtToMove is being set properly, you’re never using it to lerp to!
Second, in your Lerp function you are using Time.time. The time value should be somewhere between 0 and 1, and after the first second of your game running Time.time will always be greater than 1!
Third, you’re lerping between two values that never seem to change, so even if you were using a value between 0 and 1 for your time the position of your transform wouldn’t move unless the time value changed.

So. You need to set the target position based on the amtToMove value. Are you moving this object on the x, y, or z axis? I’m going to assume the y since you’re using a vertical slider.

function move()
    var time = Time.deltaTime;
    while (time < 1)
        transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, amtToMove, transform.position.z), time);
        time += Time.deltaTime;

Now, I don’t use unityscript, and this is untested code, but this should get you going in the right direction. Give it a shot, and if it helps you out remember to mark the question as answered! Thanks!