Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerAbilityController : MonoBehaviour {
  6.  
  7. private Animator playerAnim;
  8. public Collider footCol;
  9. public PlayerFeet PlayerFoot;
  10. public bool isActionOnGoing;
  11. public ParticleSystem GroundPunchSystem;
  12. public GameObject Projectile;
  13. public Transform projectileSpawn;
  14. private Vector3 cameraCenter;
  15. public float speed = 20f;
  16. private Animator projectileAnim;
  17.  
  18.  
  19. // Player Foot
  20. public GameObject Foot;
  21. // Is Orb at Feet
  22. public bool Orb_AtFoot = false;
  23.  
  24. // Orb Aura GameObject
  25. public GameObject OrbAura;
  26. // Is Orb Aura Attached to Player
  27. private bool OrbAuraOn;
  28. // Spawn Point of Orb Aura
  29. public GameObject OrbAuraSpawnPoint;
  30.  
  31. private bool Orb_1CanUse = true;
  32. private bool Orb_2CanUse = true;
  33.  
  34. // Enemy GameObject
  35. public GameObject enemy;
  36. // Orb Animaion
  37. private Animator OrbAnim;
  38. public bool ShootOrb;
  39.  
  40. // Use this for initialization
  41. void Start() {
  42. enemy = GameObject.FindGameObjectWithTag("Enemy");
  43. playerAnim = GetComponentInChildren<Animator>();
  44. cameraCenter = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2f, Screen.height / 2f, Camera.main.nearClipPlane));
  45.  
  46. }
  47.  
  48. // Update is called once per frame
  49. void Update() {
  50.  
  51.  
  52.  
  53. if (!isActionOnGoing)
  54. {
  55. if (Input.GetKeyDown(KeyCode.Q))
  56. PerformStandLKick();
  57. if (Input.GetKeyDown(KeyCode.Z))
  58. PerformSweepKick();
  59. if (Input.GetKeyDown(KeyCode.E))
  60. PerformStandRKick();
  61. if (Input.GetKeyDown(KeyCode.X))
  62. PerformPunch();
  63. if (Input.GetKeyDown(KeyCode.C) & !OrbAuraOn)
  64. PerformGroundPunch();
  65.  
  66. if (Input.GetKeyDown(KeyCode.G))
  67. {
  68.  
  69.  
  70.  
  71.  
  72. ShootOrb = true;
  73. if(OrbAuraOn && ShootOrb)
  74. playerAnim.SetTrigger("StandLKick");
  75. }
  76.  
  77. if (ShootOrb)
  78. {
  79. Shoot();
  80.  
  81. }
  82. }
  83. }
  84.  
  85.  
  86. // Look at Target
  87. void LookAtTarget() {
  88. gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, Quaternion.LookRotation(enemy.transform.position - gameObject.transform.position), 5f * Time.deltaTime);
  89. }
  90.  
  91. // Shoot Orb_1 & Orb_2 At Enemy
  92. void Shoot() {
  93.  
  94. // If Orb Is Availible to be shot
  95. if (Orb_1CanUse == true)
  96. {
  97. // Check if Orb Exist
  98. GameObject Orb_1 = GameObject.FindGameObjectWithTag("Orb_1");
  99.  
  100. // If Exist
  101. if (Orb_1)
  102.  
  103. {
  104. // Set Kick to True
  105. PlayerFoot.kicked = true;
  106.  
  107. // Grab Animator & Turn It Off
  108. OrbAnim = Orb_1.GetComponentInParent<Animator>();
  109. OrbAnim.enabled = false;
  110.  
  111. // Speed
  112. float speed = 12f * Time.deltaTime;
  113.  
  114.  
  115. // If Orb is not at Foot, Move Object To Foot
  116. if (!Orb_AtFoot)
  117. Orb_1.transform.position = Vector3.MoveTowards(Orb_1.transform.position, Foot.transform.position, speed);
  118. LookAtTarget();
  119.  
  120.  
  121. // If Orb At Foot, Send to Enemy
  122. if (Orb_AtFoot)
  123. {
  124. Orb_1.transform.position = Vector3.MoveTowards(Orb_1.transform.position, enemy.transform.position, speed);
  125. }
  126.  
  127.  
  128. // If Enemy Hit
  129. if (Orb_1.transform.position == enemy.transform.position)
  130. {
  131. // Destroy Orb 1
  132. Orb_1CanUse = false;
  133.  
  134.  
  135. // Reset ShootOrb
  136. ShootOrb = false;
  137.  
  138.  
  139. // Reset Is Orb At Feet
  140. Orb_AtFoot = false;
  141.  
  142.  
  143. // Destroy Orb_1
  144. Destroy(Orb_1);
  145. }
  146. }
  147. }
  148.  
  149. else if (Orb_2CanUse == true)
  150. {
  151.  
  152. GameObject Orb_2 = GameObject.FindGameObjectWithTag("Orb_2");
  153.  
  154. if (Orb_2)
  155.  
  156. PlayerFoot.kicked = true;
  157. {
  158. // Grab Animator & Turn It Off // Grab Animator & Turn It Off
  159. OrbAnim = Orb_2.GetComponentInParent<Animator>();
  160. OrbAnim.enabled = false;
  161.  
  162. // Speed
  163. float speed = 52f * Time.deltaTime;
  164.  
  165. // Move Orb 2 to Foot
  166. if (!Orb_AtFoot)
  167. Orb_2.transform.position = Vector3.MoveTowards(Orb_2.transform.position, Foot.transform.position, speed);
  168.  
  169.  
  170. // Move Orb 2 to Enemy
  171. // If Orb At Foot, Send to Enemy
  172. if (Orb_AtFoot) {
  173. Orb_2.transform.position = Vector3.MoveTowards(Orb_2.transform.position, enemy.transform.position, speed);
  174. }
  175.  
  176.  
  177.  
  178. // If Enemy Hit
  179. if (Orb_2.transform.position == enemy.transform.position)
  180. {
  181.  
  182. // Reset Orb 2
  183. Orb_2CanUse = false;
  184.  
  185.  
  186. // Reset Shooting Ability
  187. ShootOrb = false;
  188.  
  189.  
  190. // Destroy Orb 2
  191. Destroy(Orb_2);
  192.  
  193.  
  194. // Destroy Orb Aura - RESET
  195. Destroy(GameObject.FindGameObjectWithTag("OrbAura"));
  196.  
  197. // Reset OrbAura
  198. OrbAuraOn = false;
  199.  
  200. // Reset Orb Attached to Foot
  201. Orb_AtFoot = false;
  202. }
  203. }
  204. }
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211. public void PerformStandLKick() {
  212. StartCoroutine(FormatIsActionOngoingSwitch(.7f));
  213. PlayerFoot.kicked = true;
  214. playerAnim.SetTrigger("StandLKick");
  215. }
  216.  
  217.  
  218. public void PerformStandRKick() {
  219. StartCoroutine(FormatIsActionOngoingSwitch(.7f));
  220. PlayerFoot.kicked = true;
  221. playerAnim.SetTrigger("StandRKick");
  222.  
  223. }
  224.  
  225.  
  226. public void PerformSweepKick() {
  227. StartCoroutine(FormatIsActionOngoingSwitch(1f));
  228. PlayerFoot.kicked = true;
  229. playerAnim.SetTrigger("SweepKick");
  230. }
  231.  
  232.  
  233. public void PerformPunch() {
  234. StartCoroutine(FormatIsActionOngoingSwitch(.5f));
  235.  
  236. playerAnim.SetTrigger("RightPunch");
  237. }
  238.  
  239.  
  240. public void PerformGroundPunch() {
  241. // Perform Ground Punch Animation
  242. playerAnim.SetTrigger("GroundPunch");
  243.  
  244.  
  245. // Set Orb Attached to Player to True
  246. OrbAuraOn = true;
  247.  
  248.  
  249. // Call Instantated OrbAura
  250. GameObject orbAura = InstantiateAura();
  251.  
  252.  
  253. // Set Spawn Point of Orb Aura
  254. orbAura.transform.parent = OrbAuraSpawnPoint.transform;
  255.  
  256. }
  257.  
  258.  
  259. public GameObject InstantiateAura() {
  260. // Spawn OrbAura
  261. GameObject orbAura = (GameObject)Instantiate(OrbAura, OrbAuraSpawnPoint.transform.position, Quaternion.identity);
  262.  
  263.  
  264. // Set Orb 1 As Availible
  265. Orb_1CanUse = true;
  266.  
  267.  
  268. // Set Orb 2 As Availible
  269. Orb_2CanUse = true;
  270.  
  271. // Return OrbAura InGame Prefab
  272. return orbAura;
  273. }
  274.  
  275.  
  276. public void GroundPunch() {
  277. GroundPunchSystem.Play();
  278. }
  279.  
  280.  
  281. public void StandLKick() {
  282. Orb_AtFoot = true;
  283. }
  284.  
  285.  
  286. public IEnumerator FormatIsActionOngoingSwitch(float duration) {
  287. isActionOnGoing = true;
  288. yield return new WaitForSeconds(duration);
  289. isActionOnGoing = false;
  290. }
  291.  
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement