Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using Unity.VisualScripting.Antlr3.Runtime.Misc;
- using UnityEngine;
- public class PlayerAttacks : MonoBehaviour
- {
- [SerializeField] float gleamSpeed;
- [SerializeField] float domainRadius;
- [SerializeField] StatsHandler enemyStats;
- [SerializeField] int playerDamage;
- [SerializeField] LayerMask enemyLayer;
- public enum AttackEquipped {
- Melee,
- BlazingSparks,
- Gluttony,
- Domain
- }
- public AttackEquipped attackEquipped;
- void Awake()
- {
- attackEquipped = AttackEquipped.Melee;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Alpha1)) attackEquipped = AttackEquipped.Melee;
- else if (Input.GetKeyDown(KeyCode.Alpha2)) attackEquipped = AttackEquipped.BlazingSparks;
- else if (Input.GetKeyDown(KeyCode.Alpha3)) attackEquipped = AttackEquipped.Gluttony;
- else if (Input.GetKeyDown(KeyCode.Alpha4)) attackEquipped = AttackEquipped.Domain;
- Domain();
- }
- void Domain()
- {
- if (Input.GetMouseButtonUp(0) && attackEquipped == AttackEquipped.Domain)
- {
- int lowEnemyCount = 0;
- int midEnemyCount = 0;
- int highEnemyCount = 0;
- GameObject gleam;
- List<GameObject> enemies = new List<GameObject>();
- Collider[] collidersInDomain = Physics.OverlapSphere(transform.position, domainRadius);
- foreach (Collider collider in collidersInDomain)
- {
- collider.gameObject.transform.parent.gameObject.TryGetComponent<StatsHandler>(out enemyStats);
- bool isOnEnemyLayer = (enemyLayer.value & 1 <<collider.gameObject.layer) == collider.gameObject.layer;
- if (isOnEnemyLayer)
- {
- if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.LowEnemy))
- {
- lowEnemyCount ++;
- }
- else if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.MidEnemy))
- {
- midEnemyCount ++;
- }
- else if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.HighEnemy))
- {
- highEnemyCount ++;
- }
- enemies.Add(enemyStats.gameObject);
- }
- }
- foreach (GameObject enemy in enemies)
- {
- if (enemy.GetComponent<StatsHandler>().entityType == StatsHandler.EntityType.LowEnemy)
- {
- for (int lowEnemy = 0; lowEnemy < lowEnemyCount; lowEnemy ++)
- {
- gleam = Instantiate(Resources.Load("Prefabs/Gleams") as GameObject, Random.insideUnitSphere * domainRadius, (Resources.Load("Prefabs/Gleams") as GameObject).transform.rotation);
- gameObject.GetComponent<Rigidbody>().velocity = (enemy.transform.position - transform.position).normalized * gleamSpeed;
- }
- }
- }
- }
- }
- void OnDrawGizmos()
- {
- Gizmos.DrawWireSphere(transform.position, domainRadius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment