Best way to list multiple tags...

Hi all, I hate to be a bother, but I’m stuck. In a nutshell: I have a prefab cannonball that is instantiated and shot at multiple targets passing in front of a cannon when the player fires. Each target has a different tag name for gameplay reasons.
I can’t figure out how to write the script (js) so that the cannonball will explode only when it hits a gameobject collider with one of the appropriate tag names.

The script below works fine, but I’m limited to only one tag name, and I know there is a better way than putting a script for each tag on one prefab cannonball, I’m just too new at scripting to know what it is. I have searched answers, and have found solutions regarding arrays and/or variables, but none address tags specifically, and the required syntax is beyond me.

function OnCollisionEnter(myTarget : Collision) {

  if(myTarget.gameObject.tag == "Orc") {    
    
  Kaboom();
  
  }
  
  }

Thanks for any/all assistance.

P.S. Compared to most of you guys, I’m ancient and probably old enough to be your grandfather, so please be gentle :slight_smile:

You can also use | or || , the OR operators
The difference being || will skip over the rest of the matches when it finds a true, while | will perform all the tests regardless.

var tag = myTarget.gameObject.tag;
if (tag == "Orc" ||
    tag == "Goblin" ||
    tag == "GardenGnome") { 

Eric5h5’s solution is much more elegant for this, but it is worth noting that this structure also exists as it will be useful in many other situations.

You can use Array.Contains:

import System.Linq; // So Array.Contains will work

var tags = ["Orc", "Goblin", "GardenGnome"];

function OnCollisionEnter (myTarget : Collision) {
	if (tags.Contains(myTarget.gameObject.tag)) {
		DieMonsterDie();
	}
}

A tag is a string, so anything relating to strings and arrays thereof also applies to tags.