Placido_GDD

Projectile

Nov 23rd, 2021 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Projectile : MonoBehaviour
  6. {
  7.    
  8.     public string targetClass;
  9.     public string target_Tag;
  10.     public float damage_Val;
  11.     public float proj_Duration;
  12.     DroneHealth droneHealth;
  13.     ShipHealth shipHealth;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         Destroy(this.gameObject,proj_Duration);
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void OnTriggerEnter2D(Collider2D col)
  22.     {
  23.         target_Tag = col.gameObject.tag;
  24.         Debug.Log("Collided with:" + gameObject.name);
  25.         if(((target_Tag == "Enemy_I")||(target_Tag == "Player_I")) && (target_Tag != "projectile"))
  26.         {
  27.             //Debug.Log("Hit:"+col.gameObject);
  28.             droneHealth = col.gameObject.GetComponent<DroneHealth>();
  29.             droneHealth.Damage(damage_Val);
  30.             Destroy(this.gameObject);
  31.         }
  32.         if (((target_Tag == "Enemy_C") || (target_Tag == "Player_C")) && (target_Tag != "projectile"))
  33.         {
  34.             //Debug.Log("Hit:"+col.gameObject);
  35.             shipHealth = col.gameObject.GetComponent<ShipHealth>();
  36.             shipHealth.Damage(damage_Val);
  37.             Destroy(this.gameObject);
  38.         }
  39.        
  40.     }
  41. }
  42.  
Add Comment
Please, Sign In to add comment