(Solved) Bullet effect for three different objects ?

Hi.
I’m trying to make my bullet effect works in three different objects.

  • If bullet hits player don’t do anything.
    – If bullet hits enemy play blood effect destroy bullet.
    — If bullet hits any other object play dust effect and destroy bullet.
    Any thing bullet hits except those two objects “player & enemy” play dust effect and destroy bullet.
    my script play dust effect when bullet hits enemy !!
 void OnTriggerEnter(Collider bulletv)
    {

        if (bulletv.gameObject.CompareTag("enemy"))
        {
            Destroy(this.gameObject);
            Instantiate(Blood_prefab, transform.position, transform.rotation);
        }

        if (bulletv.gameObject.CompareTag("Player"))
        {
            // do not destroy
        }
        else
        {
            Instantiate(dust_prefab, transform.position, transform.rotation);
            Destroy(this.gameObject);
        }

    }

first it goes here, since its “enemy”
if (bulletv.gameObject.CompareTag(“enemy”))

but then it also goes to instantiate dust, since its there with else.

for a quick fix,
you could add return; into next line after instantiating blood, so it doesn’t continue code further.

or use switch-case instead,
or use else if (…) for the player check

1 Like

Thank you mgear.