Camera issues; objects are not showing up.
I have a camera parented to an empty object that is running the follow code. In my test scene I have a default plane, cube and an empty focus object at 0,0,0. When I attempt to run the scene the camera snaps to the correct place; however the neither the plane nor cube show up in the camera preview. In scene preview the camera's viewbox does contain the plane and cube. Camera projection has been set to Orthographic with nothing else touched from default. Not sure what is causing the issue.
using UnityEngine;
using System.Collections;
using System;
public class scr_CamMov : MonoBehaviour {
#region Variables
// references
public GameObject _Player;
public GameObject _Focus;
public GameObject _Camera;
private float distance = 10;
// making 45/45/45 degree unit vector
private static float uvVar = (float)(2 / Math.Sqrt(2));
private static Vector3 unitVector = new Vector3 (-uvVar, uvVar, -uvVar);
// camera target either player of focus point enum
enum _CameraState {
PLAYER,
FOCUS
};
_CameraState camState = _CameraState.FOCUS;
#endregion
// use this for initialization
private void Start () {
UpdateLoc(true, 0);
switch (camState) {
case _CameraState.PLAYER:
transform.LookAt(_Player.transform);
break;
case _CameraState.FOCUS:
transform.LookAt(_Focus.transform);
break;
default:
break;
}
}
// update is called once per frame
private void Update () {
}
void UpdateLoc(bool instant, float speed) {
switch (instant) {
case true:
transform.Translate(GetNewPos());
break;
case false:
transform.position = Vector3.MoveTowards(transform.position, GetNewPos(), speed);
break;
default:
transform.Translate(GetNewPos());
break;
}
}
private Vector3 GetNewPos() {
switch (camState) {
case _CameraState.PLAYER:
return _Player.transform.position + (unitVector * distance);
case _CameraState.FOCUS:
return _Focus.transform.position + (unitVector * distance);
default:
return (unitVector * distance);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612094701im_/https://answers.unity.com/themes/thub/images/avi.jpg)