Skip to content

Instantly share code, notes, and snippets.

@poemdexter
Created February 8, 2014 05:30
Show Gist options
  • Save poemdexter/8877114 to your computer and use it in GitHub Desktop.
Save poemdexter/8877114 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class PlayerSwingSword : MonoBehaviour
{
public bool isSwinging = false;
Quaternion startRotation;
Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
void Update()
{
if ((Input.GetButtonDown("Attack") || Input.GetAxis("Attack") < 0) && !isSwinging) {
isSwinging = true;
startRotation = transform.rotation;
audio.Play();
}
if (isSwinging)
animator.SetBool("isSwinging", true);
else
animator.SetBool("isSwinging", false);
}
void ResetSwordRotation()
{
transform.rotation = startRotation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment