Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

Keep GameObject size in pixels on screen by zooming camera

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>