Created
March 31, 2019 08:30
-
-
Save kmnk/534ce51a02ef067b32192f71269aefab to your computer and use it in GitHub Desktop.
VRCCamController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class VRCCamController : MonoBehaviour | |
{ | |
[SerializeField] | |
private Sprite sprite; | |
[SerializeField] | |
[Range(.1f, 10f)] | |
private float size = 5f; | |
private Transform vrcCamTransform; | |
private Camera vrcCam; | |
static readonly string vrcCamName = "/VRCCam"; | |
void SetupCamera() | |
{ | |
} | |
void Update() | |
{ | |
if (vrcCamTransform == null) | |
{ | |
var t = transform.Find(vrcCamName); | |
vrcCamTransform = t; | |
if (t != null) | |
{ | |
transform.SetParent(t); | |
transform.localPosition = new Vector3(0f, 0f, 100f); | |
transform.localRotation = Quaternion.identity; | |
t.localPosition = new Vector3(0f, 0f, -100f); | |
vrcCam = t.GetComponent<Camera>(); | |
vrcCam.orthographic = true; | |
} | |
} | |
else | |
{ | |
vrcCam.orthographicSize = size; | |
} | |
} | |
void Awake() | |
{ | |
var spriteRenderer = gameObject.AddComponent<SpriteRenderer>(); | |
spriteRenderer.sprite = sprite; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment