Advertisement
xXolitudEe

Untitled

Feb 26th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. [ExecuteInEditMode]
  7. public class PlayerMovement : MonoBehaviour {
  8.  
  9.     private Transform transform;
  10.     private Animator anim;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.         transform = GetComponent<Transform>();
  15.         anim = GetComponent<Animator>();
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         float vertical = Input.GetAxis("Vertical");
  21.         float horizontal = Input.GetAxis("Horizontal");
  22.  
  23.         if (Input.GetKey(KeyCode.W))
  24.         {
  25.             anim.SetBool("IsMoving", true);
  26.             transform.Translate(transform.rotation.x, 0, .1f);
  27.         }
  28.  
  29.         if (Input.GetKeyUp(KeyCode.W))
  30.         {
  31.             anim.SetBool("IsMoving", false);
  32.         }
  33.  
  34.         if (Input.GetKey(KeyCode.D))
  35.         {
  36.             transform.Rotate(0, 2.5f, 0);
  37.         } else if (Input.GetKey(KeyCode.A))
  38.         {
  39.             transform.Rotate(0, -2.5f, 0);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement