- Home /
Placing a GameObject on top of another GameObject.
Hey everyone,
I'm making a turn based game, similar to Final Fantasy 7, and I want to place a 3D GameObject (not related to GUI) on top of a different GameObject much like in Final Fantasy 7.
Here's an illustration to help:
From what I've been searching so far, I understand that using the renderer.bounds functions is probably the best way to go, but I'm having trouble getting the centered top!
Thank you very much in advance.
Get the position Vector3 of the object you want to place it over. Now position your floating object via this position with a +y addition to the Vector3.
Thanks for the quick answer! I really didn't think about it that way. One more thing! How can I know the height of the GameObject so I can add the precise Y value ins$$anonymous$$d of randomly testing for it?
Answer by bubzy · Nov 17, 2014 at 06:01 PM
public GameObject floatyThing;
bool flashyThing = false;
float offset = 1f;
GameObject floaty;
void Start()
{
floaty = Instantiate(floatyThing,transform.position+new Vector3(0,offset,0),Quaternion.identity) as GameObject;
floaty.SetActive(flashyThing);
}
change the value of offset
to move the thingy up and down, and change flashyThing
to turn it on and off.
this is if the flashything is above the unit you have attached the script to, otherwise you will have to do what mrsoad said and find the object.
Thanks for the answer! That seems to do the trick :) When I was reading your reply and $$anonymous$$rSoad's I came across another issue. How can I know the height of the gameobject so I can add the precise offset value, ins$$anonymous$$d of randomly testing for it?