Changing Bullet Damage from another Script

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 :slight_smile:
( I hope that made sense )

Well, I won’t go through your code and tell you how to implement this… namely because I don’t even see the code that instantiates the bullet you’re talking about… but as far as changing a value on one script from another that’s fairly easy. Here is ONE implementation that does that very thing.

    public GameObject MyBullet;
    bool IsPoweredUp;

    void CreateBullet()
    {
        GameObject ABullet = Instantiate(MyBullet);
        if (IsPoweredUp)
        {
            ABullet.GetComponent<BulletScript>().PowerUpFunction();
        }    
    }

Another implementation might involve increasing the damage of all bullets, including active ones… so this SECOND implementation does the same thing basically, but should work in conjunction with the one above… (as this one does not change the damage of future bullets

void PowerUpBullets()
{
    foreach(GameObject bullet in GameObject.FindGameObjectsWithTag("Bullets"))
    {
        bullet.GetComponent<BulletScript>().PowerUpFunction();
    }
}