Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: detomato on February 19, 2014, 08:14:54 PM

Title: Transform object with slider.
Post by: detomato on February 19, 2014, 08:14:54 PM
Hi, this probably an easy to answer which obviously not so easy for me.

I would like to use the slider to transform a game object, especially its rotation and scale. I look through if there is any integration with Playmaker, but still hitting the wall.
So I would like to know if there's easy way to do so?

Thanks.
Title: Re: Transform object with slider.
Post by: ArenMook on February 20, 2014, 10:41:37 AM
Here's an example. Attach this script to the object you want rotated, and in the slider's On Change script choose this script's SliderChange function as the notification target.
  1. using UnityEngine;
  2.  
  3. public class MyScript : MonoBehaviour
  4. {
  5.     public void SliderChange ()
  6.     {
  7.         transform.localRotation = Quaternion.Euler(0f, 0f, 180f * UISlider.current.value));
  8.     }
  9. }
Title: Re: Transform object with slider.
Post by: detomato on February 21, 2014, 01:59:05 AM
Here's an example. Attach this script to the object you want rotated, and in the slider's On Change script choose this script's SliderChange function as the notification target.
  1. using UnityEngine;
  2.  
  3. public class MyScript : MonoBehaviour
  4. {
  5.     public void SliderChange ()
  6.     {
  7.         transform.localRotation = Quaternion.Euler(0f, 0f, 180f * UISlider.current.value));
  8.     }
  9. }

Thanks for the script. But how does it work if I got 2 slider?
Title: Re: Transform object with slider.
Post by: ArenMook on February 21, 2014, 03:08:50 PM
You're the one who sets the On Change notification on the slider. If you have two sliders, choose scripts on different objects.
Title: Re: Transform object with slider.
Post by: detomato on February 22, 2014, 02:13:50 AM
You're the one who sets the On Change notification on the slider. If you have two sliders, choose scripts on different objects.
hi, thanks for the reply. Manage to get it to work, but it only working on the Z-axis. I tried to change to 180f, 0f, 0f but nothing happen.
I know Im missing the very obvious here. Please have mercy. :)

Thanks!

edit: Its working now, not sure if its the most elegant way to do so, but at least its working.
Title: Re: Transform object with slider.
Post by: detomato on February 22, 2014, 02:51:30 AM
Please forgive my ignorance, but can I get a quick help with the scaling scripts?

  1. public void SliderChange ()
  2.         {
  3.                 transform.localScale = new Vector3(2, 2, 2) * (UISlider.current.value);
  4.         }

I end up with the codes above which kinda works, but it scales to 0 when the slider is at the lowest value. I want to scale it from the current scale. If you get what I mean. :)

Thanks in advance.
Title: Re: Transform object with slider.
Post by: ArenMook on February 22, 2014, 11:11:05 AM
You seem to be asking really basic Unity-related questions here. You know how to get the slider's value -- UISlider.current.value. The rest is about how to use Unity, not NGUI. This is a support forum for NGUI, not Unity.
  1. transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 2f * UISlider.current.value);