So I’m trying to create power-ups for my game but can’t figure out how to change the damage int that’s in the projectile script through the power-up script. I’m trying to increase the bullet damage for 5 seconds but all the methods I’ve tried won’t work. When I tried the different methods I didn’t get any errors but nothing is changing the int. The script is:
public int multiplier = 5;
public float duration = 5f;
public GameObject DamageUI;
public GameObject damageBar;
public GameObject pickupEffect;
public GameObject parent;
void Awake()
{
DamageUI.SetActive(false);
damageBar.SetActive(false);
GetComponent<SpriteRenderer>().enabled = true;
GetComponent<Collider2D>().enabled = true;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
StartEffects(other);
}
}
void StartEffects(Collider2D other)
{
Debug.Log("Trying to Start Coroutine");
StartCoroutine(Pickup(other));
StartCoroutine(AnimationDelay());
}
IEnumerator Pickup(Collider2D player)
{
DamageUI.SetActive(true);
damageBar.SetActive(true);
Instantiate(pickupEffect, transform.position, transform.rotation);
// CHANGE BULLET DAMAGE TO *= MULTIPLIER
GetComponent<SpriteRenderer>().enabled = false;
GetComponent<Collider2D>().enabled = false;
yield return new WaitForSeconds(duration);
// CHANGE BULLET DAMAGE TO /= MULTIPLIER
Destroy(gameObject);
Destroy(parent);
}
IEnumerator AnimationDelay()
{
yield return new WaitForSeconds(5);
DamageUI.SetActive(false);
damageBar.SetActive(false);
}
I’m trying to change the int that’s attached to the projectile that is instantiating everytime I click, here’s the code that I’m using:
[Header("Bullet Stats")]
public float speed;
public int damage;
public float lifeTime;
public float distance;
[Space]
public LayerMask whatIsSolid;
public GameObject destroyEffect;
// Use this for initialization
public void Start () {
Invoke("DestroyProjectile", lifeTime);
}
// Update is called once per frame
private void Update ()
{
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, distance, whatIsSolid);
if(hitInfo.collider != null)
{
if(hitInfo.collider.CompareTag("Enemy"))
{
Debug.Log("Hit Enemy || Taken damage");
hitInfo.collider.GetComponent<Enemy>().TakeDamage(damage);
}
DestroyProjectile();
}
transform.position += transform.up * speed;
}
void DestroyProjectile()
{
Instantiate(destroyEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Someones help would really be apreciated, thank you for your time
( I hope that made sense )