how to set the button to attack?

i have a code like this , when i press Q attack animation plays. i want to set this to UI button how can i do that?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCombatController : MonoBehaviour
{

Animator animator;

private void Start()
{
animator = GetComponent<Animator>();
}

private void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.Space))
{
animator.SetTrigger("attack");
}

}

}

Let me google that for you.

This is the 2D features forum, the dedicated UI forum is here. Also, as indicated above, much easier to perform a simple search which reveals an almost endless set of tutorials on the Unity UI system.

1 Like