- Home /
how many tags is too many
Hi I have a room which is a 3d website, there are many objects 28 at the last count, that the user can click on to take them to normal websites or many different web documents. is it ok to have that many tags or is there another way I should be doing this? They all trigger different web pages in a similar way to this code.
function OnMouseUp(){
if (collider.gameObject.tag == "MFG_Display_Stand" && guiOff == false){
Application.OpenURL ("http://www1.plymouth.ac.uk/faith/Pages/default.aspx");}}
Thanks in advance
Tim
Answer by Owen-Reynolds · May 28, 2013 at 02:58 PM
Most people would probably just use the object's name for something like that. Tags are more for quickly grouping classes of objects. Like, ummm, G, PG, Must be 18 (in a regular game, might be Enemy, Loot, DestructableWall.)
But, then for anything complicated, can put a script on each object. For example have a string URL variable, so other designers can click on the object and enter the web page in the Inspector (and they can send it to you as a prefab.) No need to open up the code to add/change objects.
$$anonymous$$mm the main reason i ask is that i have a script that stops interaction with other objects in the scene. and its getting very long now i was wondering if i was doing the right thing, or is there an easier/less complicated way of doing it.
Answer by Tarlius · May 29, 2013 at 11:25 AM
Its hard to know without seeing more of your project, but it sounds to me like you have a room, and in this room you have many different objects that the user can click on (via an fps camera + "shooting" it/etc) to open pages.
For this kind of project, you would probably be better off having a "WebpageOpener" script that you attach to each individual object, that opens a webpage you link in the inspector, rather than making a "god object" that holds all of them. Your code will be much shorter and easier to maintain.
If you have an object that can open any one of many pages, you will probably want to look into making an array of some kind to hold them all, rather than adding individual fields for each.
yeah array sounds like an idea for the objects i want to stop interaction with.
I do have a script on each object that kicks off a url. The room is a web based player and not being able to kick off a new window really sucks, i have used window.open in my html.
the code linking is to hard to explain atm my brain is mush. oh w8 i wrote a help file.... this explains to a user how to add the code to the object in the scene(I think its too geeky).
Could you tell me how to add an array of scripts that need to be linked to the "locker" script. Like in step 8 of the help file. or would it be pointless to link loads of other scripts in an array.
html format link: http://web-design-3d.co.uk/help%20files/How%20to%20add%20an%20object%20with%20a%20weblink.htm
pdf format link: http://web-design-3d.co.uk/pdf_folder/How%20to%20add%20an%20object%20with%20a%20weblink.pdf
I think you would be better off restructuring so that ins$$anonymous$$d of an "else if(hit.collider.gameObject.tag = XYZ)" you do something more like
CodeHolder holder = hit.collider.gameObject.GetComponent<CodeHolder>();
if(holder != null) {
// Do something with holder.code, for example
}
This way to add an item you just make a new game object for the object to touch, then grab the script from it. You won't need to edit the code at all, only the scene (which you already are anyway).
Your answer
![](https://koobas.hobune.stream/wayback/20220613103057im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Text Mesh Pro : How to override standard text styling tags ? (bold, underline, etc ...) 0 Answers
Are tag settings passed down from Game Object parent to mesh child? 1 Answer
Is it possible to have my character latch to an object? 1 Answer
Creating tags via code 3 Answers
Deleting gameobject with tag problem 1 Answer