Advertisement
Guest User

thirdPersonController.cs

a guest
Jan 4th, 2014
1,537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class thirdPersonController : MonoBehaviour
  5. {
  6.     public static CharacterController charController;   // Reference to player's character controller
  7.     public static thirdPersonController instance;       // Reference to itself
  8.  
  9.     void Awake ()
  10.     {
  11.         charController = GetComponent<CharacterController> ();
  12.         instance = this;
  13.         thirdPersonCamera.UseExistingOrCreateMainCamera ();
  14.     }
  15.  
  16.     void Update ()
  17.     {
  18.         if (Camera.main == null)
  19.         {
  20.             return;
  21.         }
  22.         GetLocomotionInput ();
  23.         HandleActionInput ();
  24.  
  25.         thirdPersonMotor.instance.UpdateMotor ();
  26.     }
  27.  
  28.     public void GetLocomotionInput ()
  29.     {
  30.         float deadZone = 0.1f;                                  // Leeway distance that is ignored.
  31.  
  32.         thirdPersonMotor.instance.verticalVelocity = thirdPersonMotor.instance.moveVector.y;
  33.         thirdPersonMotor.instance.moveVector = Vector3.zero;
  34.  
  35.         // Match moveVector.z to vertical input
  36.         if (Input.GetAxis ("Vertical") > deadZone || Input.GetAxis ("Vertical") < -deadZone)
  37.         {
  38.             thirdPersonMotor.instance.moveVector += new Vector3(0,0, Input.GetAxis("Vertical"));
  39.         }
  40.  
  41.         // Match moveVector.x to horizontal input
  42.         if (Input.GetAxis ("Horizontal") > deadZone || Input.GetAxis ("Horizontal") < -deadZone)
  43.         {
  44.             thirdPersonMotor.instance.moveVector += new Vector3(Input.GetAxis ("Horizontal"), 0, 0);
  45.         }
  46.  
  47.         // Get direction.
  48.         thirdPersonAnimator.instance.DetermineCurrentMoveDirection ();
  49.     }
  50.  
  51.     private void HandleActionInput ()
  52.     {
  53.         if (Input.GetButton ("Jump"))
  54.         {
  55.             Jump ();
  56.         }
  57.     }
  58.  
  59.     private void Jump ()
  60.     {
  61.         thirdPersonMotor.instance.Jump ();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement