Advertisement
Guest User

thirdPersonAnimator.cs

a guest
Jan 4th, 2014
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class thirdPersonAnimator : MonoBehaviour
  5. {
  6.     public static thirdPersonAnimator instance;         // Self reference
  7.  
  8.     public enum Direction
  9.     {
  10.         Stationary, Forward, Backward, Left, Right,
  11.         LeftForward, RightForward, LeftBackward, RightBackward
  12.     }
  13.  
  14.     public Direction moveDirection { get; set; }
  15.  
  16.     private void Awake ()
  17.     {
  18.         instance = this;
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update ()
  23.     {
  24.    
  25.     }
  26.  
  27.     public void DetermineCurrentMoveDirection ()
  28.     {
  29.         bool forward = false;
  30.         bool backward = false;
  31.         bool left = false;
  32.         bool right = false;
  33.  
  34.         if (thirdPersonMotor.instance.moveVector.z > 0)
  35.             forward = true;
  36.  
  37.         if (thirdPersonMotor.instance.moveVector.z < 0)
  38.             backward = true;
  39.  
  40.         if (thirdPersonMotor.instance.moveVector.x > 0)
  41.             right = true;
  42.  
  43.         if (thirdPersonMotor.instance.moveVector.x < 0)
  44.             left = true;
  45.  
  46.         if (forward)
  47.         {
  48.             if (left)
  49.                 moveDirection = Direction.LeftForward;
  50.             else if (right)
  51.                 moveDirection = Direction.RightForward;
  52.             else
  53.                 moveDirection = Direction.Forward;
  54.         }
  55.         else if (backward)
  56.         {
  57.             if (left)
  58.                 moveDirection = Direction.LeftBackward;
  59.             else if (right)
  60.                 moveDirection = Direction.RightBackward;
  61.             else
  62.                 moveDirection = Direction.Backward;
  63.         }
  64.         else if (left)
  65.             moveDirection = Direction.Left;
  66.         else if (right)
  67.             moveDirection = Direction.Right;
  68.         else
  69.             moveDirection= Direction.Stationary;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement