Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.AI;
  6. using UnityEngine.EventSystems;
  7.  
  8. public class PlayerController : MonoBehaviour
  9. {
  10. #region Private Members
  11.  
  12. public Animator _animator;
  13.  
  14. public CharacterController _characterController;
  15.  
  16. public float Gravity = 14.5f;
  17.  
  18. public Vector3 _moveDirection = Vector3.zero;
  19.  
  20.  
  21. private int startHealth;
  22.  
  23. private int startFood;
  24.  
  25. #endregion
  26.  
  27. #region Public Members
  28.  
  29. public float Speed = 5.0f;
  30.  
  31. public float RotationSpeed = 240.0f;
  32.  
  33. public GameObject Hand;
  34.  
  35.  
  36. public float JumpSpeed = 5.00f;
  37.  
  38. public float verticalVelocity;
  39.  
  40. public int myIndex;
  41. #endregion
  42.  
  43. // Use this for initialization
  44. public Transform AttachPoint;
  45. public Transform CharacterAttach;
  46. public CharacterState currentState { get; set; }
  47.  
  48. public CharacterState previusState { get; set; }
  49.  
  50. public IdleState Idle { get; protected set; }
  51. public WalkState WalkState { get; protected set; }
  52. public JumpState JumpState { get; protected set; }
  53. public MagicCombatState MagicCombatState { get; protected set; }
  54.  
  55. public string currentAnim { get; set; }
  56. public bool projectileSent { get; set; }
  57. public string effectName { get; set; }
  58. public NavMeshAgent navAgent;
  59. public Transform Destination;
  60. public Skill skill { get; set; }
  61.  
  62. void Start()
  63. {
  64. navAgent = GetComponent<NavMeshAgent>();
  65. GameManager.instance.playerList[myIndex].AddComponent<RFX4_EffectEvent>();
  66. _animator = GetComponent<Animator>();
  67. _characterController = GetComponent<CharacterController>();
  68.  
  69.  
  70. Idle = gameObject.AddComponent<IdleState>();
  71. WalkState = gameObject.AddComponent<WalkState>();
  72. JumpState = gameObject.AddComponent<JumpState>();
  73. MagicCombatState = gameObject.AddComponent<MagicCombatState>();
  74.  
  75. currentState = Idle;
  76. currentState.enabled = true;
  77.  
  78. }
  79.  
  80. #region Inventory
  81.  
  82.  
  83. private int Attack_1_Hash = Animator.StringToHash("Base Layer.Attack_1");
  84.  
  85. public bool IsAttacking
  86. {
  87. get
  88. {
  89. AnimatorStateInfo stateInfo = _animator.GetCurrentAnimatorStateInfo(0);
  90. if (stateInfo.fullPathHash == Attack_1_Hash)
  91. {
  92. return true;
  93. }
  94. return false;
  95. }
  96. }
  97.  
  98.  
  99. #endregion
  100.  
  101. #region Health & Hunger
  102.  
  103. [Tooltip("Amount of health")]
  104. public int Health = 100;
  105.  
  106. [Tooltip("Amount of food")]
  107. public int Food = 100;
  108.  
  109. [Tooltip("Rate in seconds in which the hunger increases")]
  110. public float HungerRate = 0.5f;
  111.  
  112. public void IncreaseHunger()
  113. {
  114. Food--;
  115. if (Food < 0)
  116. Food = 0;
  117.  
  118.  
  119. if (IsDead)
  120. {
  121. CancelInvoke();
  122. _animator.SetTrigger("death");
  123. }
  124. }
  125.  
  126. public bool IsDead
  127. {
  128. get
  129. {
  130. return Health == 0 || Food == 0;
  131. }
  132. }
  133.  
  134. public bool IsArmed
  135. {
  136. get
  137. {
  138. return false;
  139. }
  140. }
  141.  
  142.  
  143. public void Eat(int amount)
  144. {
  145.  
  146.  
  147. }
  148.  
  149. public void Rehab(int amount)
  150. {
  151.  
  152. }
  153.  
  154. public void TakeDamage(int amount)
  155. {
  156.  
  157.  
  158. }
  159.  
  160. #endregion
  161.  
  162.  
  163. void FixedUpdate()
  164. {
  165. if (!IsDead)
  166. {
  167.  
  168. }
  169. }
  170.  
  171. private bool mIsControlEnabled = true;
  172.  
  173. public void EnableControl()
  174. {
  175. mIsControlEnabled = true;
  176. }
  177.  
  178. public void DisableControl()
  179. {
  180. mIsControlEnabled = false;
  181. }
  182. // Update is called once per frame
  183. private void InitPoitns()
  184. {
  185. Transform[] obj = GetComponentsInChildren<Transform>(true);
  186. foreach (var ob in obj.Where(ob => (ob != transform)))
  187. {
  188. if (ob.name == "RightForeArmTwist")
  189. {
  190. AttachPoint = ob;
  191. }
  192. if (ob.name == "RightShoulder")
  193. {
  194. CharacterAttach = ob;
  195. }
  196. Debug.Log(ob.name);
  197. }
  198. GameManager.instance.playerList[myIndex].GetComponent<RFX4_EffectEvent>().AttachPoint = AttachPoint;
  199. GameManager.instance.playerList[myIndex].GetComponent<RFX4_EffectEvent>().CharacterAttachPoint = CharacterAttach;
  200. GameManager.instance.playerList[myIndex].GetComponent<RFX4_EffectEvent>().Effect = Resources.Load("Effect1") as GameObject;
  201. }
  202.  
  203.  
  204. void Update()
  205. {
  206. if(AttachPoint == null)
  207. {
  208. InitPoitns();
  209. }
  210. if (_animator == null)
  211. {
  212. _animator = GetComponent<Animator>();
  213. _animator.applyRootMotion = true;
  214. }
  215.  
  216. currentState.UpdateState();
  217. currentState.ProcessInput();
  218. currentState.MovementMotor();
  219.  
  220. if (!IsDead && mIsControlEnabled)
  221. {
  222.  
  223.  
  224. }
  225. }
  226.  
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement