Could anyone please tell me how to set a GameObject Tag to a 3D Object through a script please?
I really appreciate your help.
Could anyone please tell me how to set a GameObject Tag to a 3D Object through a script please?
I really appreciate your help.
GameObject.gameObject.tag=“Player”;
gameObject.tag should be enough.
Yeah you are correct! Thanks man! 8)
Hey, just in case anyone has this problem because I also did, The tag has to be one word.
gameObject.tag = “Main Camera” is wrong,
gameObject.tag = “MainCamera” is right
no, tags can have spaces.
If you are trying to use the functionality of
Camera.Main.
you just need to use the “correct” spelling for that function, i.e.
Tags should also be set up in the tag manager before use.
is there any way to give a GameObject a Tag through a Script without setting the tag up in the tag manager before Scripting it?
You have to set a tag in the tag manager beforehand and then, in the script, you can assign it (for example, if you take a key you can change the tag of doors from “Closed” to “Open”, as long as the “Open” tag exists in the tag manager).
As far as I know, you can’t create a tag at runtime.
At editor time you can use an editor script to create a new tag.
At runtime you are better off implementing your own tagging system if you need to create new tags.
Hello,
Can anyone help me with this script? i want to tag more gameobjects with this script ,but i don’t know how to do it.
Any help would be appreciated
The script (javascript):
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == “Door4v2”) // here i want to tag another gameobject
{
guiShow = true;
if(Input.GetKeyDown(“e”) && isOpen == false)
{
i have a game object. clicking it should change its tag to another. pls help!!!
Unity tagging system is very poorly designed. Use it where appopriate, but if you want to heavily rely on tags in your game consider buying something better from asset store or writing your own.
Why? Im using TAGS since ages and not even a problem and im relying heavily on them. Please explain why Unity Tags are so bad designed, because in here it works.
String comparisons.
Say you decide to change or remove a tag; now you must sift through every reference in every script in your project and change or remove the references from those places as well.
The best you could do to prevent this is to create a global static class holding constant string values of each Unity tag, and reference these constants instead of typing in tag names directly, but you would still need to manually edit this class when changing tags and other classes as well when removing tags.
If editing Unity tags compiled an enum during edit-time containing string literals of each tag you specify, I’d likely be using them more.
Ever needed to place two different tags onto the same GameObject?
@Vryken Can i just open an IDE and put Search And Replace? For example, tag: let’s put “Ugly_Orc” tag here.
Then i go to change the tag 3 months later (why?). If i change the tag name i will never know
why the OnTrigger function that it is looking (sorry my english again) for this tag, it is working.
So, in the first place, i will try to not change the tag. But if i need to, then Search And Replace
will be my friend. But i work just on 1 game and sporadic apps, so, i dont know in wich environment
this will be a heavy problem. Of course if the Editor just tell me with a Popup: If you change this
tag name all your references inside all your scripts will be lost, are you sure? I see the point
about this as bad designed now. So i agree about it is risky and needs an improvement.
Oh god, never change the name of the tag. Will instantly kill you.
@Kiwasi No. WHY? ! haha. But maybe yes. I had to use the GameObject name as “tag” i think (because i cannot have 2 tags in same GameObject scenario) and compare against the GameObject name and the Tag, or just put a child with another Tag.
It’s tag maze.
Looks like already are familiar with the limitations of tags.
these limitations are probably caused by unity’s compiler rendering tags as an integer, to be used as an index in a list of tags controlled by the tag manager. this is useless, because no one is going around making 200 character tags anyways. but i’m still just fine using tags.
If my game object was called Custom_player Current How would I do this?
(I want to add a tag “player” to my player so I can have zones where certain sound plays)
thx if you answer!