Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerAbilityController : MonoBehaviour {
- private Animator playerAnim;
- public Collider footCol;
- public PlayerFeet PlayerFoot;
- public bool isActionOnGoing;
- public ParticleSystem GroundPunchSystem;
- public GameObject Projectile;
- public Transform projectileSpawn;
- private Vector3 cameraCenter;
- public float speed = 20f;
- private Animator projectileAnim;
- // Player Foot
- public GameObject Foot;
- // Is Orb at Feet
- public bool Orb_AtFoot = false;
- // Orb Aura GameObject
- public GameObject OrbAura;
- // Is Orb Aura Attached to Player
- private bool OrbAuraOn;
- // Spawn Point of Orb Aura
- public GameObject OrbAuraSpawnPoint;
- private bool Orb_1CanUse = true;
- private bool Orb_2CanUse = true;
- // Enemy GameObject
- public GameObject enemy;
- // Orb Animaion
- private Animator OrbAnim;
- public bool ShootOrb;
- // Use this for initialization
- void Start() {
- enemy = GameObject.FindGameObjectWithTag("Enemy");
- playerAnim = GetComponentInChildren<Animator>();
- cameraCenter = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2f, Screen.height / 2f, Camera.main.nearClipPlane));
- }
- // Update is called once per frame
- void Update() {
- if (!isActionOnGoing)
- {
- if (Input.GetKeyDown(KeyCode.Q))
- PerformStandLKick();
- if (Input.GetKeyDown(KeyCode.Z))
- PerformSweepKick();
- if (Input.GetKeyDown(KeyCode.E))
- PerformStandRKick();
- if (Input.GetKeyDown(KeyCode.X))
- PerformPunch();
- if (Input.GetKeyDown(KeyCode.C) & !OrbAuraOn)
- PerformGroundPunch();
- if (Input.GetKeyDown(KeyCode.G))
- {
- ShootOrb = true;
- if(OrbAuraOn && ShootOrb)
- playerAnim.SetTrigger("StandLKick");
- }
- if (ShootOrb)
- {
- Shoot();
- }
- }
- }
- // Look at Target
- void LookAtTarget() {
- gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, Quaternion.LookRotation(enemy.transform.position - gameObject.transform.position), 5f * Time.deltaTime);
- }
- // Shoot Orb_1 & Orb_2 At Enemy
- void Shoot() {
- // If Orb Is Availible to be shot
- if (Orb_1CanUse == true)
- {
- // Check if Orb Exist
- GameObject Orb_1 = GameObject.FindGameObjectWithTag("Orb_1");
- // If Exist
- if (Orb_1)
- {
- // Set Kick to True
- PlayerFoot.kicked = true;
- // Grab Animator & Turn It Off
- OrbAnim = Orb_1.GetComponentInParent<Animator>();
- OrbAnim.enabled = false;
- // Speed
- float speed = 12f * Time.deltaTime;
- // If Orb is not at Foot, Move Object To Foot
- if (!Orb_AtFoot)
- Orb_1.transform.position = Vector3.MoveTowards(Orb_1.transform.position, Foot.transform.position, speed);
- LookAtTarget();
- // If Orb At Foot, Send to Enemy
- if (Orb_AtFoot)
- {
- Orb_1.transform.position = Vector3.MoveTowards(Orb_1.transform.position, enemy.transform.position, speed);
- }
- // If Enemy Hit
- if (Orb_1.transform.position == enemy.transform.position)
- {
- // Destroy Orb 1
- Orb_1CanUse = false;
- // Reset ShootOrb
- ShootOrb = false;
- // Reset Is Orb At Feet
- Orb_AtFoot = false;
- // Destroy Orb_1
- Destroy(Orb_1);
- }
- }
- }
- else if (Orb_2CanUse == true)
- {
- GameObject Orb_2 = GameObject.FindGameObjectWithTag("Orb_2");
- if (Orb_2)
- PlayerFoot.kicked = true;
- {
- // Grab Animator & Turn It Off // Grab Animator & Turn It Off
- OrbAnim = Orb_2.GetComponentInParent<Animator>();
- OrbAnim.enabled = false;
- // Speed
- float speed = 52f * Time.deltaTime;
- // Move Orb 2 to Foot
- if (!Orb_AtFoot)
- Orb_2.transform.position = Vector3.MoveTowards(Orb_2.transform.position, Foot.transform.position, speed);
- // Move Orb 2 to Enemy
- // If Orb At Foot, Send to Enemy
- if (Orb_AtFoot) {
- Orb_2.transform.position = Vector3.MoveTowards(Orb_2.transform.position, enemy.transform.position, speed);
- }
- // If Enemy Hit
- if (Orb_2.transform.position == enemy.transform.position)
- {
- // Reset Orb 2
- Orb_2CanUse = false;
- // Reset Shooting Ability
- ShootOrb = false;
- // Destroy Orb 2
- Destroy(Orb_2);
- // Destroy Orb Aura - RESET
- Destroy(GameObject.FindGameObjectWithTag("OrbAura"));
- // Reset OrbAura
- OrbAuraOn = false;
- // Reset Orb Attached to Foot
- Orb_AtFoot = false;
- }
- }
- }
- }
- public void PerformStandLKick() {
- StartCoroutine(FormatIsActionOngoingSwitch(.7f));
- PlayerFoot.kicked = true;
- playerAnim.SetTrigger("StandLKick");
- }
- public void PerformStandRKick() {
- StartCoroutine(FormatIsActionOngoingSwitch(.7f));
- PlayerFoot.kicked = true;
- playerAnim.SetTrigger("StandRKick");
- }
- public void PerformSweepKick() {
- StartCoroutine(FormatIsActionOngoingSwitch(1f));
- PlayerFoot.kicked = true;
- playerAnim.SetTrigger("SweepKick");
- }
- public void PerformPunch() {
- StartCoroutine(FormatIsActionOngoingSwitch(.5f));
- playerAnim.SetTrigger("RightPunch");
- }
- public void PerformGroundPunch() {
- // Perform Ground Punch Animation
- playerAnim.SetTrigger("GroundPunch");
- // Set Orb Attached to Player to True
- OrbAuraOn = true;
- // Call Instantated OrbAura
- GameObject orbAura = InstantiateAura();
- // Set Spawn Point of Orb Aura
- orbAura.transform.parent = OrbAuraSpawnPoint.transform;
- }
- public GameObject InstantiateAura() {
- // Spawn OrbAura
- GameObject orbAura = (GameObject)Instantiate(OrbAura, OrbAuraSpawnPoint.transform.position, Quaternion.identity);
- // Set Orb 1 As Availible
- Orb_1CanUse = true;
- // Set Orb 2 As Availible
- Orb_2CanUse = true;
- // Return OrbAura InGame Prefab
- return orbAura;
- }
- public void GroundPunch() {
- GroundPunchSystem.Play();
- }
- public void StandLKick() {
- Orb_AtFoot = true;
- }
- public IEnumerator FormatIsActionOngoingSwitch(float duration) {
- isActionOnGoing = true;
- yield return new WaitForSeconds(duration);
- isActionOnGoing = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement