- Home /
OnClick() animation
I am trying to add the ability to do dances in my game, and i would like to make a script that when i or the person presses a certain button which then activates the dance for a moment then reverts back to original idle position. I have animations for walking and being idle but im not sure how to do what im trying to do If anyone can help me thatd be great:) below is my movement script that ties into my animations for walking
using UnityEngine;
public class PlayerMovement2 : MonoBehaviour {
private CharacterController characterController;
private Animator animator;
private HealthBar2 mHealthBar;
//public HUD Hud;
[SerializeField]
private float moveSpeed = 100;
[SerializeField]
private float turnSpeed = 5f;
private void Awake()
{
characterController = GetComponent<CharacterController>();
animator = GetComponentInChildren<Animator>();
}
private void Update ()
{
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
//var movement = new Vector3(horizontal, 0, vertical);
animator.SetFloat("Speed", vertical);
transform.Rotate(Vector3.up, horizontal * turnSpeed * Time.deltaTime);
if (vertical !=0)
{
characterController.SimpleMove(transform.forward * moveSpeed * vertical);
}
}
void Start()
{
//mHealthBar = Hud.transform.Find("HealthBar").GetComponent<HealthBar2>();
mHealthBar.Min = 0;
mHealthBar.Max = Health;
}
public int Health = 100;
public void TakeDamage(int amount)
{
Health -= amount;
if (Health < 0)
Health = 0;
mHealthBar.SetHealth(Health);
}
}
Your answer
Follow this Question
Related Questions
How do I make a function not appear on UnityEvents / Button OnClick lists? 0 Answers
changing script from key based function to GUI button for dice roll game 1 Answer
Creating working UI Button from Script? 1 Answer
Change text value 3 Answers
Why won't my function show up in the onClick area of a button? 2 Answers