Advertisement
SizilStank

Untitled

Feb 9th, 2023
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Laser : MonoBehaviour
  6. {
  7.  
  8.     [SerializeField] private float _laserSpeed = 1f;
  9.     [SerializeField] private float _destroyGameObejectAtYPos = 6.8f;
  10.  
  11.     [SerializeField] private GameObject _enemyExplosion;
  12.     [SerializeField] private float _enemyExplosionTime = 0.4f;
  13.  
  14.     [SerializeField] private AudioManager _audioManager;
  15.  
  16.     private void Start()
  17.     {
  18.         _audioManager = GameObject.Find("AudioManager").GetComponent<AudioManager>();
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.  
  25.         transform.Translate(Vector3.up * _laserSpeed * Time.deltaTime);
  26.  
  27.         if (transform.position.y >= _destroyGameObejectAtYPos)
  28.         {
  29.             if (transform.parent != null)
  30.             {
  31.                 Destroy(transform.parent.gameObject);
  32.             }
  33.  
  34.             Destroy(this.gameObject);
  35.         }
  36.     }
  37.  
  38.     private void OnTriggerEnter2D(Collider2D collision)
  39.     {
  40.         if (collision.CompareTag("Asteroid"))
  41.         {
  42.             Destroy(this.gameObject);
  43.         }
  44.  
  45.         if (collision.CompareTag("EnemyLaser"))
  46.         {
  47.             GameObject explosion = Instantiate(_enemyExplosion, transform.position, Quaternion.identity);
  48.  
  49.             Destroy(explosion, _enemyExplosionTime);
  50.  
  51.             _audioManager.PlayEnemyExplosionSound();
  52.         }
  53.  
  54.         if (collision.CompareTag("EnemyA"))//Subing to the EventManager
  55.         {
  56.             EventManager.OnLaserCollected();//this is the event that the event manager is listining for
  57.         }
  58.  
  59.         if (collision.CompareTag("ResetLaserCount"))//Subing to the EventManager this is a tag on the box collider
  60.         {
  61.             EventManager.OnSubtractLaserCollected();//this is the event that the event manager is listining for
  62.         }
  63.  
  64.         if (collision.CompareTag("Boss"))
  65.         {
  66.             GameObject explosion = Instantiate(_enemyExplosion, transform.position, Quaternion.identity);
  67.  
  68.             Destroy(explosion, _enemyExplosionTime);
  69.         }
  70.  
  71.         if (collision.CompareTag("Boss01"))//Subing to the EventManager this is a tag on the Boss01 Spawn
  72.         {
  73.             EventManager.OnRemoveBoss01FromList();//this is the event that the event manager is listining for
  74.  
  75.             GameObject explosion = Instantiate(_enemyExplosion, transform.position, Quaternion.identity);
  76.  
  77.             Destroy(explosion, _enemyExplosionTime);
  78.         }
  79.     }
  80.  
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement