- Home /
Position GameObject to Bottom Left Corner
i am having game object which i want to position to bottom left corner of the screen.. Bcz if i directly position my game object then it appears at different different position according to mobile device screen size..
So what should i do to position gameobject same like GUI..
Pleaze Give Me some Solution..
Thanx For Your Support and Help in advance..
Adjust/place screen.width = 0; screen.height = screen.height-50;
ok.. all these i need to assign my gameobject's position..?? can u please explain in detail??
Answer by whebert · Apr 16, 2013 at 01:07 PM
You can use Camera.ScreenToWorldPoint to accomplish that. The Vector3 that you use in the call to ScreenToWorldPoint will be the screen pixel location in X,Y (0,0 at bottom left) and the Z will be distance from the camera. See reference.
using UnityEngine;
using System.Collections;
public class ObjectInFrontOfCamera : MonoBehaviour {
public GameObject objectTarget;
public Vector3 screenPosition = new Vector3(0,0,20);
// Use this for initialization
void Start () {
if(objectTarget != null)
{
objectTarget.transform.position = camera.ScreenToWorldPoint(screenPosition);
}
}
}
ok sir.. but if i am having one empty parent Object which z position is -10.. Under that parent object i am having three child.. and all that child is having different z distance.. so in position which value do i need to keep ?? or any other idea is there for same??
Answer by Linus · Apr 16, 2013 at 12:24 PM
Making the object a child of the main camera, and then position it should work.
You might be interested in nGUI or a similar solution. There is a free version, but to publish game it does cost some money.