
Thanks for Help, just wondering if i can generalise a tag towards these SpriteRenders and Collide2Ds, or if there is any other method to tackle this. Im new and this is urgent because its congesting my work flow. Thanks Again
FYI:
these SpriteRenders and Collide2Ds are all children of a single GameObject.
Firstly, the only reason for anyone to ask any question on this site is because they’re stuck trying to achieve something required for their game. I’m really struggling to see how your request is any more URGENT than anyone elses’s.
Secondly, it’s really unclear what you want. The only code snippet you’ve posted (well, screenshot of a code snippet) is just some public variable declarations. What do you want to do with those variables?
Whatever you’re trying to achieve, I’d suggest that it could be substantially improved by the use of arrays. You can replace the entire of your screenshot with this:
public GameObject theShield;
public SpriteRenderer[] theShieldSprites;
public Collider2D[] theShieldColliders;
Why don’t you use an array to manage all those objects? And why do you create a new SpriteRenderer and Collider2D for each of them? … It’s kind of chaotic. I don’t really understand what you are trying to do…
However, I suggest you to use a prefab for this. Create a prefab in the editor with all you need for a single object you want to add to your host ‘theShield’, I guess. Make it public and reference it in the editor, then, whenever you need it, you just add an instance through your code with Instantiate ( prefab_name, theShield): this will set theShield as the parent…
Even better, create a class for that parent. That is something that needs to be managed on its own.
And for the tag, you just write object_name.tag = tag_name. Just make sure you add the tag you’d like to use in your editor first.