UI Slider Wont Work when i add event trigger to handle
UI slider Wont Work properly when i add event trigger to handle .
is there any way to fix this ?
you mean just adding the EventTrigger component results in the slider not working anymore? I doubt that. Please be more precise on what you did and try to get the slider working and slowing working towards the problem first.
Okay let me explain more :) for reproduce this problem , add UI slider to scene , find handle in hierarchy (hierarchy>canvas>Slider>Handle Slide Area > Handle) Add Event Trigger.
after this steps, you can not move slider by draging handle, but you can adjust slider value by clicking it.
so what should i do for solve this problem.
Answer by SohailBukhari · Mar 29, 2017 at 06:51 AM
Attaching Event Trigger Means You are using your custom events to move slider knob.So if you want to move custom knob as your on way then handle its events in the script and assign in the event.
you are pointed a good point . i understand now why this problem occurs but still havent figure it out how to make it works. but thanks :)
i am trying to use slider as catapult , like when you drag the handle and release it it fires an arrow . so i added onPointerDown and onPointerUp events to handle , bu this time i cannot slide hanlde trough slider because as you said its drag event isn't handling by slider anymore. i got this, but still dont know what to do for fix this.
Using onPointerDown means event will fire when you keep finger on your object and onPointerUp means event will not fire continuously.
Ins$$anonymous$$d of using onPointerDown and onPointerUp events use the onValueChanged event of slider class.
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class SliderChangeValue: $$anonymous$$onoBehaviour
{
public Slider mainSlider;
public void Start()
{
//Adds a listener to the main slider and invokes a method when the value changes.
mainSlider.onValueChanged.AddListener (delegate {ValueChangeCheck ();});
}
// Invoked when the value of the slider changes.
public void ValueChangeCheck()
{
Debug.Log (mainSlider.value);
}
}
onValueChange wont get my job done , because i need to know when player released "knob"