Created
May 8, 2017 07:24
-
-
Save William-ST/2eaf694a077b25b558ef6873a59fd55f to your computer and use it in GitHub Desktop.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/* https://www.mixamo.com */ | |
public class Drive : MonoBehaviour { | |
float speed = 5.0F; | |
float rotationSpeed = 100.0F; | |
Animator anim; | |
void Start() { | |
anim = this.GetComponent<Animator> (); | |
} | |
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); | |
anim.SetFloat ("characterSpeed", translation); | |
} else { | |
anim.SetBool ("isWalking", false); | |
anim.SetFloat ("characterSpeed", 0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment