Hi, so I am making a tower defense game and I am making it so my particles shoot out of a tower, and when those particles hit the object, it does damage to it. I got that down but now I am trying to make it so you can upgrade the towers. I got it so the upgraded towers get placed down but the problem is the enemy only cares about hits from a tower with the script tower on it. So I made a script called towerlevel2 that does more damage than just the regular tower script. So how do I make it so that enemy knows how much damage to do based on which tower shot it. Thanks! Here is the script that does damage to the enemy:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyTrigger : MonoBehaviour
{
[SerializeField] int hitPoints;
[SerializeField] GameObject explosion;
[SerializeField] EnemyMovement enemyMovement;
[SerializeField] ParticleSystem hit;
[SerializeField] GameObject atEndParticles;
[SerializeField] float waitToDestroyAtEnd;
[SerializeField] AudioClip hitSFX;
[SerializeField] AudioClip explosionSFX;
[SerializeField] AudioClip shootSFX;
TextController textController;
PlayerHealth playerHealth;
Tower tower;
public bool isDead = false;
bool atEnd = false;
void Awake()
{
tower = GameObject.Find("Tower").GetComponent<Tower>();
textController = GameObject.Find("Text Controller").GetComponent<TextController>();
}
void OnParticleCollision(GameObject other)
{
Damage();
Explode();
}
void Damage()
{
GetComponent<AudioSource>().PlayOneShot(hitSFX, 5);
GetComponent<AudioSource>().PlayOneShot(shootSFX);
hit.Play();
hitPoints = hitPoints - tower.damagePerHit;
}
void Explode()
{
if (hitPoints <= 0)
{
BoxCollider enemyBoxCollider = gameObject.GetComponent<BoxCollider>();
enemyBoxCollider.enabled = false;
isDead = true;
enemyMovement.isMoving = false;
explosion.SetActive(true);
GetComponent<AudioSource>().PlayOneShot(explosionSFX);
textController.points = textController.points + textController.pointIncrease;
textController.scoreText.text = textController.points.ToString();
Invoke("Destroy", 1f);
}
}
void Destroy()
{
Destroy(gameObject);
}
void OnTriggerStay()
{
atEnd = true;
Invoke("CheckIfDead", waitToDestroyAtEnd);
}
void CheckIfDead()
{
if (isDead == true)
{
return;
}
else if (isDead == false && atEnd == true)
{
GameObject spawnedParticles = Instantiate(atEndParticles, gameObject.transform.position, Quaternion.identity);
Destroy(spawnedParticles, waitToDestroyAtEnd);
playerHealth = GameObject.Find("Friendly_Base").GetComponent<PlayerHealth>();
playerHealth.HurtFriendlyBase();
Destroy();
}
}
}