- Home /
SetBool and SetTrigger not work on UI button click in unity
Hello friends i am having a problem in unity ui button i used the SetBool in a function and also i used the SetTrigger in each function now when i call that function with the keyboard keys it is working but when i use the ui buttons and even if i use the on click or OnPointerUp and OnPointerDown methods which are available in event system the ui button is not working and also there are no console errors. I have also searched many websites but many of the peoples asked for this problem years ago and it was not solved. Also my project is going to build for android. Kindly Help me in this problem. I was also having this problem in my old projects.
could you please elaborate and provide some videos and source code ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimation : MonoBehaviour
{
public Animator playerAnimator;
private void Update()
{
}
public void Idel()
{
playerAnimator.SetBool("RunChange", false);
playerAnimator.SetBool("JumpChange", false);
playerAnimator.SetInteger("IdelIndex", Random.Range(0, 8));
playerAnimator.SetTrigger("IdelTrigger");
playerAnimator.SetBool("IdelStateMachineChange", true);
}
public void Run()
{
playerAnimator.SetBool("IdelStateMachineChange", false);
playerAnimator.SetBool("RunChange", true);
playerAnimator.SetBool("JumpChange", false);
}
public void Jump()
{
playerAnimator.SetBool("JumpChange", true);
playerAnimator.SetTrigger("JumpTrigger");
playerAnimator.SetInteger("JumpIndex", Random.Range(0, 7));
playerAnimator.SetBool("IdelStateMachineChange", false);
Debug.Log("It is pressed.");
}
}
In the upper source code the ui button is for calling jump function