- Home /
Question by
GameDevH2O · Oct 06, 2018 at 11:22 PM ·
camera2dgameobjectscale
How to scale gameobject width with camera?
Hello I have a platform that I’m trying to scale the width with the camera in a orthographic view. My script stretches it out too much any help?
public Camera mainCam;
public GameObject ground;
void Update ()
{
ground.transform.localScale = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width * 1f, 0f, 0f)).x, 1f);
}
Comment
I'm not sure why you would need ScreenToWorldPoint here. Does this do what you need?
ground.transform.localScale = new Vector2(2f * mainCam.orthographicSize * mainCam.aspect, 1f);
I adjusted the 2f to a value that suited the game but this worked fine thank you.