Created
October 6, 2017 06:35
-
-
Save AndrewWeston9/ebcb7b008dea9a36c6286e7a01b5a49b to your computer and use it in GitHub Desktop.
Animation controller for the player character. Controls walking and gathering animations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Networking; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System; | |
public class PlayerAnimator : NetworkBehaviour { | |
public Animator anim; | |
public float speed = 2.0f; | |
public float rotationSpeed = 75.0f; | |
int timer = 0; | |
// Use this for initialization | |
void Start () { | |
anim = this.GetComponent<Animator> (); | |
} | |
// Update is called once per frame | |
void Update () { | |
float translation = Input.GetAxis ("Vertical") * speed; | |
float rotation = Input.GetAxis ("Horizontal") * rotationSpeed; | |
translation *= Time.deltaTime; | |
rotation *= Time.deltaTime; | |
transform.Translate (0, 0, translation); | |
transform.Rotate (0, rotation, 0); | |
if (translation != 0) { | |
anim.SetBool ("isWalking", true); | |
} else { | |
anim.SetBool ("isWalking", false); | |
} | |
if (Input.GetKey (KeyCode.G) || Input.GetKey (KeyCode.E)) { | |
anim.SetBool ("isGathering", true); | |
timer = 30; | |
} else { | |
timer -= 1; | |
if (timer < 0) { | |
anim.SetBool ("isGathering", false); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment