Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRory Letteney
1,342 PointsDropdown UI instantiation position - C# Unity
Hello! I have instantiated a few planes, and I would like to create a drop-down menu at the location of the plane when each one is clicked. Everything is working as it should be, except for one small detail. The drop-downs are always created at the center of the viewport. When I debug.log the drop-down's position it says the same Vector3 as the plane that was clicked, but it obviously isn't at the same location.
[SerializeField]
private Transform groundTile;
[SerializeField]
private GameObject dropdown;
private GameObject dropdownGameObject;
private bool clicked;
void Start () {
clicked = false;
}
void OnMouseOver()
{
if (Input.GetMouseButtonUp(0) && clicked == false)
{
dropdownGameObject = Instantiate(dropdown);
dropdownGameObject.transform.SetParent(groundTile, false);
dropdownGameObject.transform.position = groundTile.position;
Debug.Log(dropdownGameObject.transform.position);
clicked = true;
}
}
void OnMouseExit()
{
Destroy(dropdownGameObject);
clicked = false;
}