Guest User

Untitled

a guest
Oct 28th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using Unity.VisualScripting.Antlr3.Runtime.Misc;
  3. using UnityEngine;
  4.  
  5. public class PlayerAttacks : MonoBehaviour
  6. {
  7.     [SerializeField] float gleamSpeed;
  8.     [SerializeField] float domainRadius;
  9.     [SerializeField] StatsHandler enemyStats;
  10.     [SerializeField] int playerDamage;
  11.     [SerializeField] LayerMask enemyLayer;
  12.     public enum AttackEquipped {
  13.         Melee,
  14.         BlazingSparks,
  15.         Gluttony,
  16.         Domain
  17.     }
  18.     public AttackEquipped attackEquipped;
  19.     void Awake()
  20.     {
  21.         attackEquipped = AttackEquipped.Melee;
  22.     }
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.        if (Input.GetKeyDown(KeyCode.Alpha1))    attackEquipped = AttackEquipped.Melee;
  27.        else if (Input.GetKeyDown(KeyCode.Alpha2))   attackEquipped = AttackEquipped.BlazingSparks;
  28.        else if (Input.GetKeyDown(KeyCode.Alpha3))   attackEquipped = AttackEquipped.Gluttony;
  29.        else if (Input.GetKeyDown(KeyCode.Alpha4))   attackEquipped = AttackEquipped.Domain;
  30.        
  31.        Domain();
  32.     }
  33.     void Domain()
  34.     {
  35.         if (Input.GetMouseButtonUp(0) && attackEquipped == AttackEquipped.Domain)
  36.         {
  37.             int lowEnemyCount = 0;
  38.             int midEnemyCount = 0;
  39.             int highEnemyCount = 0;
  40.             GameObject gleam;
  41.             List<GameObject> enemies = new List<GameObject>();
  42.             Collider[] collidersInDomain = Physics.OverlapSphere(transform.position, domainRadius);
  43.  
  44.             foreach (Collider collider in collidersInDomain)
  45.             {
  46.                 collider.gameObject.transform.parent.gameObject.TryGetComponent<StatsHandler>(out enemyStats);
  47.                 bool isOnEnemyLayer = (enemyLayer.value & 1 <<collider.gameObject.layer) == collider.gameObject.layer;
  48.                 if (isOnEnemyLayer)
  49.                 {
  50.                     if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.LowEnemy))
  51.                     {
  52.                         lowEnemyCount ++;
  53.                     }
  54.                     else if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.MidEnemy))
  55.                     {
  56.                         midEnemyCount ++;
  57.                     }
  58.                     else if (isOnEnemyLayer && enemyStats.entityType.Equals(StatsHandler.EntityType.HighEnemy))
  59.                     {
  60.                         highEnemyCount ++;
  61.                     }
  62.  
  63.                     enemies.Add(enemyStats.gameObject);
  64.                 }
  65.             }
  66.  
  67.             foreach (GameObject enemy in enemies)
  68.             {
  69.                 if (enemy.GetComponent<StatsHandler>().entityType == StatsHandler.EntityType.LowEnemy)
  70.                 {
  71.                     for (int lowEnemy = 0; lowEnemy < lowEnemyCount; lowEnemy ++)
  72.                     {
  73.                         gleam = Instantiate(Resources.Load("Prefabs/Gleams") as GameObject, Random.insideUnitSphere * domainRadius, (Resources.Load("Prefabs/Gleams") as GameObject).transform.rotation);
  74.                         gameObject.GetComponent<Rigidbody>().velocity = (enemy.transform.position - transform.position).normalized * gleamSpeed;
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.     }
  80.     void OnDrawGizmos()
  81.     {
  82.         Gizmos.DrawWireSphere(transform.position, domainRadius);
  83.     }
  84. }
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment