Hey, I was wondering if I click on a game object could it change it's own tag and if another game object has the same tag it's tag to be changed as well. Something like I have two tags- TagA and TagB; I have a cube and another cube; Both cubes have TagB but when I click on the first one then it will change it's tag to TagA and then I click on the second one and it would change it's tag to TagA and the first one would change it's tag to TagB- is that possible?
I tried this:
using UnityEngine;
using System.Collections;
public class Tagging : MonoBehaviour {
void OnMouseDown()
{
GameObject[] SP = GameObject.FindGameObjectsWithTag("Respawn");
foreach (GameObject go in SP)
{
if (go != this.gameObject)
{
gameObject.tag = "Player";
}
}
if (gameObject.tag == "Player")
{
gameObject.tag = "Respawn";
}
else if (gameObject.tag == "Respawn")
{
gameObject.tag = "Player";
}
}
but it isn't working any suggestions?
↧