OnTriggerEnter2D how to make an if statement for two tags which are the same
Hi, I am making a paper, rock, scissor game where two player meet in the middle of a map. When the player uses up and down they change between the 3 sprites (rock, paper, scissor) and I also made it change its tag (rock, paper, scissor tags).
Now I am trying to make them collide and want to destroy the correct one. How can I make the OnTriggerEnter2D detect 2 tags - one from each player?
Here is my current "Clash" code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Clash : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Scissor")
{
if(other.gameObject.tag == "Scissor")
{
Debug.Log("Draw!");
}
else Debug.Log("Scissor wins agains paper!");
}
}
}
I also tried this which worked but I couldnt figure out if two of the same sprite collided (e.g. paper and paper). void OnTriggerEnter2D(Collider2D other) if (other.gameObject.CompareTag("Scissor")) { Debug.Log("Rock wins!"); Debug.Log(other.tag); if (other.gameObject.tag == "Paper") { Debug.Log("Paper wins!"); Debug.Log(other.tag); } Destroy(GameObject.FindWithTag("Scissor")); }