- Home /
How to get a real time position of an instantiated object?
For example, I have a RectTransform UI element moving about the screen. Inside its script, there is a position condition to trigger an event at a certain position. How do I do that inside the script?
Answer by tormentoarmagedoom · May 06, 2019 at 11:19 AM
Hello.
Its simple, when you instantiate an object, you can simply instantiate it, or Instantiate at same time you store that object as a variable, so you can "manipulate" that object. Like this:
GameObject InstantiatedObject;
GameObject PrefabToInstantiate;
InstantiatedObject = Instantiate(PrefabToInstantiate, position, rotation);
Now, you have the instantiated object stored as InstantiatedObject variable, so you can just check its position, change it, or do anything you want like any other gameobject. As its a CAnvas element, it does not have transform, it have RectTransfrom, so read the manual about this component for more information. The position is the anchoredPosition value, you can check it like this:
if (InstantiatedObject.GetComponent<RectTransform>().anchoredPosition.x >= 3.2f)
{
something
}
Bye!
Your answer

Follow this Question
Related Questions
Setting a Rect from another RectTransform 0 Answers
iPhone Droid Input.GetTouch(i).position 4 Answers
Limiting Game Object position by rect 1 Answer
Rect Transform local position to gameobject position 1 Answer
Inspector Rect position 2 Answers