Quantcast
Channel: Questions in topic: "tagging"
Viewing all articles
Browse latest Browse all 120

How can I change the tags of a different object if I click on this one and do so in reverse?

$
0
0
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?

Viewing all articles
Browse latest Browse all 120

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>