Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 trmodel3 · Sep 10, 2019 at 07:09 AM · uisoundslider

How to add sound to the movement of the radial slider

alt text I want to make a sound when the temperature display radial slider in the above figure is rotated.

In the above UI, the light blue handle rotates.

The sound clicks every time it is rotated by 0.5 ° C, and I want to make a single sound continuous so that when I turn the handle, it clicks.

Below is a script with a radial slider attached to the light blue handle object in the figure.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class PointCircle4 : MonoBehaviour, IDragHandler
 {
     [Range(0f, 1f)]
     public float value;
 
     public float radius;
     public float min;
     public float max;
     public TemperatureText temperatureText;
 
     RectTransform rectTransfrom;
 
     Vector2 parentPosition;
 
 
     public void Start()
     {
         rectTransfrom = GetComponent<RectTransform>();
         parentPosition = rectTransfrom.parent.transform.position;
     }
 
 
     public void OnDrag(PointerEventData data)
     {
         var diff = new Vector2(data.position.x - parentPosition.x, data.position.y - parentPosition.y);
         float radian = Mathf.Atan2(diff.y, diff.x);
 
         if (radian < -Mathf.PI / 2f)
         {
             radian += Mathf.PI * 2f;
         }
         radian = Mathf.Clamp(radian, min, max);
         value = 1f - Mathf.InverseLerp(min, max, radian);
     }
 
     public void SetValue(float value)
     {
         this.value = value;
     }
 
     public void Update()
     {
         float radian = Mathf.Lerp(min, max, 1 - value);
         //rectTransfrom.localPosition = new Vector2(Mathf.Cos(radian), Mathf.Sin(radian)) * radius;
 
         Vector3 dir = new Vector2(Mathf.Cos(radian), Mathf.Sin(radian));
         rectTransfrom.localPosition = dir * radius;
         rectTransfrom.localRotation = Quaternion.LookRotation(Vector3.forward, dir);
 
 
 
         temperatureText.value = value;
     }
 }

If you add an AudioSource to the object, how can you make it sound when the slider rotates?

The operation this time is moved by a variable resistor via Uduino.

I think the following part of the script is related to the event function.

 public void SetValue(float value)
 {
 this.value = value;
 }

222.jpg (51.5 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

0 Replies

· Add your reply
  • Sort: 

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

190 People are following this question.

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

Related Questions

How to put a image under a powerbar's handle thats moving? 0 Answers

In terms of performance, is changing the position of a whole canvas better than changing the position of a UI element? 1 Answer

Dynamic slider size with the new UI 2 Answers

left end of slider fill flattening the more i move the value down 0 Answers

Why hip will move upward and downward automatically when start to drag slider at x,y and z axis? 0 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