Hello everyone,
I’m trying to make a Drill with some interactive buttons as exercise to learn Unity. I made one button to activated the drill so you can see the tool spinning and a slider to control the speed in the GUI.
But I have problems trying to synchronize a GUI slider with a 3d Object “VariableSpeedAdjuster” with animation attached , so when the GUI slider is moving the 3d object too.
I made one script for the GUI buttons with a Slider and other for the 3d Object “VariableSpeedAdjuster” and finally another for the rotor or motor.
I’m trying to get to work my script, but I can’t.
Please any advice is more than welcome. Thanks in advance
Script Number 1
GUI & Slider Script.
static var triggerGo : int;
static var cameraGo : 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);
GUI.skin = Skin_power;
if (GUI.Button(Rect(870,227,80,56),"")){
audio.PlayOneShot(beep);
triggerGo = (triggerGo + 1) % 2;
}
}
Script Number 2
And this is my other Script for the 3D object to be interact with my GUI Slider.
static var vSliderValue : int;
var myAnimation : AnimationState;
function Start(){
myAnimation = animation["VariableSpeedAdjuster"];
}
function LateUpdate() {
myAnimation.time = vSliderValue;
myAnimation.enabled = true;
animation.Sample();
myAnimation.enabled = false;
}
Script Number 3
Motor or Rotor
function Update () {
amtToMove =buttonsGUI. vSliderValue * Time.deltaTime;
if (buttonsGUI .triggerGo == 1){
transform.Rotate(0,buttonsGUI. vSliderValue * Time.deltaTime,0);
}
}
[6712-3d+object+or+3d+slider.jpg|6712]