- Home /
Question by
kevindapkus · Mar 21 at 05:10 PM ·
onclick
onclick.addlistener only works on the second click,onclick.addlistener only working on second click
i have an onclick.add listener to trigger a fade from black to normal whenever a button is clicked but for some reason the fade only triggers the second time the button is clicked i even added a debug.log to the start and end of the listener and it still only shows up on the second click this is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OptionsFade : MonoBehaviour
{
[SerializeField] RectTransform fader;
public Button Options;
void Start()
{
Options.onClick.AddListener(TaskOnClick);
}
public void TaskOnClick()
{
Debug.Log("start");
fader.gameObject.SetActive(true);
LeanTween.alpha(fader, 1, 0);
LeanTween.alpha(fader, 0, 0.5f).setOnComplete(() =>
{
fader.gameObject.SetActive(false);
});
Debug.Log("done");
}
}
Comment