using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
namespace Invector.CharacterController
{
public class ThirdPersonController : ThirdPersonAnimator
{
private static ThirdPersonController _instance;
public static ThirdPersonController instance
{
get
{
if (_instance == null)
{
_instance = GameObject.FindObjectOfType<ThirdPersonController>();
//Tell unity not to destroy this object when loading a new scene
//DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
private bool isAxisInUse;
void Start()
{
InitialSetup(); // setup the basic information, created on Character.cs
Cursor.visible = false;
}
//////This is where the external functions begin////////////
void FixedUpdate()
{
UpdateMotor(); // call ThirdPersonMotor methods
UpdateAnimator(); // update animations on the Animator and their methods
UpdateHUD(); // update HUD elements like health bar, texts, etc
ControlCameraState(); // change CameraStates
}
void LateUpdate()
{
InputHandle(); // handle input from controller, keyboard&mouse or mobile touch
DebugMode(); // display information about the character on PlayMode
}
/// <summary>
/// INPUT - every input is been handle in this script, you can change the input map here or directly on the InputManager
/// </summary>
void InputHandle()
{
CloseApp ();
CameraInput ();
if (!lockPlayer && !ragdolled) {
ControllerInput ();
// we have mapped the 360 controller as our Default gamepad,
// you can change the keyboard inputs by chaging the Alternative Button on the InputManager.
InteractInput ();
JumpInput ();
RollInput ();
CrouchInput ();
AttackInput ();
DefenseInput ();
SprintInput ();
LockOnInput ();
DropWeaponInput ("D-Pad Horizontal");
} else
LockPlayer ();
}
////The Input ///////////////
/// <summary>
/// CONTROLLER INPUT - gets input from keyboard, gamepad or mobile touch to move the character
/// </summary>
public void ControllerInput()
{
if (inputType == InputType.Mobile)
input
= new Vector2
(CrossPlatformInputManager
.GetAxis ("Horizontal"), CrossPlatformInputManager
.GetAxis ("Vertical")); else if (inputType == InputType.MouseKeyboard)
input
= new Vector2
(Input
.GetAxis ("Horizontal"), Input
.GetAxis ("Vertical")); else if (inputType == InputType.Controler) {
float deadzone = 0.25f;
input
= new Vector2
(Input
.GetAxis ("LeftAnalogHorizontal"), Input
.GetAxis ("LeftAnalogVertical")); if (input.magnitude < deadzone)
input = Vector2.zero;
else
input = input.normalized * ((input.magnitude - deadzone) / (1 - deadzone));
}
}
}