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…
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??
Adjust/place screen.width = 0; screen.height = screen.height-50;
– Shankarok.. all these i need to assign my gameobject's position..?? can u please explain in detail??
– Ekta-Mehta-D