Hi all, I have a top-down perspective camera view of an object in my scene.
I'm exporting for WebGL, and I want to start off the scene with a top-down view of the object, but I need it to remain the same size in screen pixels no-matter the width/height of the Unity player on the web page.
I want to achieve this by moving the camera up/down (along the y axis), but I'm struggling with the maths needed to calculate the correct y position of the camera.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCamera : MonoBehaviour {
private Camera cam;
public Transform target;
void Start () {
cam = GetComponent();
}
void Update () {
float newY = /*unknown calculation*/;
transform.position = new Vector3(transform.position.x, newY, transform.position.z);
}
}
↧