Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by paco morales · Jan 15, 2013 at 02:47 AM · animationslider3dobject

Synchronize a GUI slider with a 3d Object?

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);

} }

Screenshot

3d object or 3d slider.jpg (124.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CodeMasterMike · Jan 15, 2013 at 08:28 AM

I have little problem reading the script code, but here is a simple example on how you can do it:

 private float m_currentValue    = 0.0f;
 private float m_topValue        = 1.0f;
 private float m_bottomValue     = 0.0f;
 
 private Vector3 m_offPosition   = new Vector(0.0f, 0.0f, 0.0f);
 private Vector3 m_onPosition    = new Vector(1.0f, 1.0f, 1.0f);
 
 public GameObject m_3dObjectSlider = null;
 
  
  OnGUI()
  {
     // Slider goes between 0.0 and 1.0, or you can see it as 0% to 100%
     m_currentValue = GUI.VerticalSlider(position, m_currentValue, m_topValue, m_bottomValue);
     m_3dObjectSlider.transform.Position = Vector3.Lerp(m_offPosition, m_onPosition, m_currentValue);    
  }

So, I setup the slider GUI object to slide between 0.0 and 1.0. And I use this value to Lerp the position of the 3d object. Now, I don't know the exact positions for the object, so I just put in some values, that you need to change.

But as you pull the slider in any direction, the 3d object should also slide between these two vectors.

I haven't tested this code, its just a example, but I hope you can see the idea behind it and change the code around until it works for you and your project.

Good luck!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paco morales · Jan 15, 2013 at 03:25 PM 0
Share

Hi $$anonymous$$ike, Let $$anonymous$$e try it :)

Thanks

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Mecanim, weapon bone animation woe... 1 Answer

How can I read time from clip that is PlayQueued? 1 Answer

I made a menu with NGUI and I would like to know how to give to an slider functionality 1 Answer

I am trying to sync a slider to an animation. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges