-1

I have the following and it's not working. I would like to include more than one tag in this if statement. I just started learning c# and would really appreciate some help.

if (hit.collider.gameObject.tag == "test" && "craft")
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
tjkso
  • 141
  • 8
  • 4
    `if (hit.collider.gameObject.tag == "test" && hit.collider.gameObject.tag =="craft")` – bansi Jan 10 '17 at 05:43
  • 1
    @bansi `||` must surely be what the OP wants! – Ken Y-N Jan 10 '17 at 05:45
  • It does not work because "&& "craft"" is not a condition. You should make a compare with "craft" (ex: variable == "craft") instead. – GSP Jan 10 '17 at 05:45
  • if (hit.collider.gameObject.tag.Equals("test") || hit.collider.gameObject.tag.Equals("craft")) { //Your logic here } Use the Logical OR operator, ||. If the first statement is evaluated to true, the second will not be tested – monstertjie_za Jan 10 '17 at 05:51
  • @KenY-N looks like yes. Just answered the question. – bansi Jan 10 '17 at 05:51

2 Answers2

-2

No it wont work that way use if (hit.collider.gameObject.tag == "test" && hit.collider.gameObject.tag =="craft")

dgorti
  • 1,130
  • 2
  • 12
  • 22
-2

If (var1 == "string1" && var2 == "string2")