I am trying to use the OnMouseDrag function to slow down the speed at which a UI slider can be moved. I am using a UI slider to scrub through an animation. I want to limit the speed at which the slider can be moved by the user so that the animation runs smoothly. So far I haven't managed to solve the issue. The script I am using has been attached. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class sliderscript : MonoBehaviour { public void OnMouseDrag () { Vector3 MousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition); MousePos.z = 0.2f; transform.position = MousePos; } }
Do you think the OnValueChanged of the slider could maybe help you and limit the next move to a small amount of time in the future?
This could be a potential solution, however I wouldn't know how to implement this as I have very little coding experience.
Unity makes things fun and easy, but there's nearly no way to avoid programming. You can get a long way with even some knowledge. It's good to try to learn the basics. Not sure if this is exactly what you're looking for... Code (csharp): public class Test13 : Slider { float nextTime = 0; float currentValue = 0; bool changed = false; public void SliderValueChanged(float val) { changed = true; } void LateUpdate() { if (!changed) return; if (Time.time < nextTime) { value = currentValue; changed = false; return; } if (value < currentValue) currentValue--; else if (value > currentValue) currentValue++; value = currentValue; nextTime = Time.time + .4f; changed = false; } }
I am keen to learn more about programming, its just that I have a deadline so learning what I need is difficult.
It baffles me when people say they have a deadline, and thus "skip learning". How can that even equate? (this is not the first time I've heard that..) heh. Hope it works for ya. I mean, when I tested it, it worked as far as restricting the slider's movement. Beyond that scope, I can't say
Not skip learning as such, but having to look to find solutions in short spaces of time. Thus, making it difficult to learn what I want. I want to learn how to create code, but in some cases my knowledge of coding wont allow me to solve the problem in time for the deadline.
I just don't understand what it means in general. Is this for school? How can there be a deadline that is too constrained to give you the time to learn what you need? Anyways.. let me know how the code works lol
Deadline meaning I need to deliver something by a set time, however I don't have the time to learn and implement what I need within the time frame I am given.
Sorry, you have to delete the original slider script, eh? Did you do that? I mean that's how I wrote it.. could probably change that.. but just delete the original and remember to put the 3 parts linked back in (that the original has.. references to parts of the slider).
I knew what you meant, and not to keep going off topic, but how could you be given a deadline that you can't reach by learning or doing.. just seems strange to me.
Just the way things have turned out. I am a student and my lecturers have poorly organised the course.
I deleted the slider component and added your script. I than added the references. The printscreen below shows what I have done.
I see. Okay, in my example I was using whole numbers 1 - 10 (to be specific) for testing. Try that.. and see if you even like it before doing more changes. Of course for 0 - 1.0f you'd have to modify the values a bit.
Oh, and you should add an OnValueChanged event for the method in the class there.'SliderValueChanged'. I can't see if that's so in your screenshot.
I have added the SliderValueChanged method to the OnValueChanged event. The slider moves much slower now, however it doesn't seem to move smoothly. I have tried playing around with the values but the smoothness of the slider doesn't seem to change.
Well, in the sense that I didn't consider that from your original question I was only thinking you wanted its value to change more slowly..
I am trying to use the OnMouseDrag function to slow down the speed at which a UI slider can be moved. I am using a UI slider to scrub through an animation. I want to limit the speed at which the slider can be moved by the user so that the animation runs smoothly. So far I haven't managed to solve the issue. The script I am using has been attached." My original question is shown above, stating that I would like the animation to run smoothly. Thus the slider would have to be moved smoothly.