- Home /
Generate a unique id for a pair of objects
So I need to get all objects in between other objects, which come in pairs, left and right objects. That´s easy, is just comparing positions. The problem is that when more than one pair of objects is active, one left can be interpreted as the left of the wrong right, and viceversa. In most cases I don´t know how many objects will be there, so basically am asking if there´s a way of identifying these pairs of gameObjects, like with an id or something like that; then do something only if both have the same id.
I'm sorry I couldn't get the idea of the what you want the script to do...
Sorry, it´s clamping the scale of a single/group of grounds if there´s a rigidbody in between 2 baseObjects, left and right. The scale of the ground below decreases and stops when that happens; but this can be happening multiple times in the same level, which means that sometimes this affects some incorrect grounds. (The affected ground is between leftA and rightA, not, for example, leftA and rightB).
Answer by Nivbot · Nov 08, 2018 at 05:40 AM
Are they instantiated? When I need to reference a list of instantiated objects I normally keep track of how many there are and just rename them by the number there are. ie. if there are 21 then when you instantiate a new pair they will be LeftObject_22 RightObject_22. Sometimes I use a for loop. It just depends on what you need.
GameObject LeftObj = (GameObject)Intstantiate(Resources.Load("whatever"));
currentCount++
LeftObj.name = "LeftObject_" + currentCount.ToString();
might not need .ToString() but I normally put it anyway. I've noticed before that not using it didn't throw an error but I do it just to be safe.
Answer by Matt1000 · Nov 08, 2018 at 02:05 AM
You could have the baseObjects have a
public GameObject other;
and set it in the inspector. For example, leftA would have a reference to rightA and vice-versa. So, if your script finds leftA and a right, it should check if right is the same as leftA.other.
Hope it helps ;)
Thanks, but it´s more complicated than that. The rigidbodies can be arranged in different ways, so the other isn´t constant.
Your answer
Follow this Question
Related Questions
GetInstanceID ?????? 2 Answers
Is SystemInfo.deviceUniqueIdentifier reliable? 1 Answer
How to set component ID when adding it to the inspector? 0 Answers
How to use GUIUtility functions? 1 Answer
ID or name for Instantiate prefab 1 Answer