SebastianLawe

Untitled

Mar 5th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Diagnostics;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.     public float input = 0;
  7.     public float speed = 0.5f;
  8.     Animator animator;
  9.     Rigidbody rigidbody;
  10.     // Use this for initialization
  11.     void Start() {
  12.         animator = GetComponent<Animator>();
  13.         rigidbody = GetComponent<Rigidbody>();
  14.     }
  15.  
  16.     void FixedUpdate() {
  17.         float newSpeed = speed;
  18.         rigidbody.AddRelativeForce(new Vector3(Input.GetAxisRaw("Horizontal") * newSpeed, 0, input = Input.GetAxisRaw("Vertical") * newSpeed), ForceMode.VelocityChange);
  19.         animator.SetFloat("Movement", Mathf.Abs(rigidbody.velocity.x) + Mathf.Abs(rigidbody.velocity.z));
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update() {
  24.  
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment