Need to get the either…or if statement to work. By this I mean if condition A or B is met. According the ref guide, the " | " symbol is used (ex. if (x == 1 | 2 | 3). I want to use it for three separate objects : “targ1” “targ2” “targ3”. I haven’t found the correct syntax to do this for object names or tags.
function OnCollisionEnter(shotCollide : Collision)
{
if (shotCollide.gameObject.name ==("targ1" | "targ2" | "targ3")) //this syntax is wrong
{
if(!shotCollide.gameObject.rigidbody)
{
shotCollide.gameObject.AddComponent(Rigidbody);
}
}
}
var name = "targ1";
//All of these return true for targ1, targ2 and targ3... but vary in *how* strict they are and how flexible.
Console.WriteLine("targ1targ2targ3".Contains(name)); //Warning, this returns true for 'g1tar' etc.
Console.WriteLine(new[] { "targ1", "targ2", "targ3" }.Contains(name));
Console.WriteLine(name == "targ1" || name == "targ2" || name == "targ3");
int temp;
Console.WriteLine(name.StartsWith("targ") //any suffix is fine
int.TryParse(name.Remove(0, 4), out temp) //any integer suffix
temp > 0 temp < 4); //within a certain range.
Console.ReadLine();