Hi all, quick problem with cameras here.
I’ve got two seats, each with a camera at the head position, with a mouselook and a raycast script attached. What is supposed to happen is when the user click on a seat, the camera switches to that one. It works fine when I start in chair1 and switch to chair2, but when i switch back to chair1 the screen goes blank grey. The statistics panel shows zero draw calls and zero tris/verts, but I can mouse the camera right and click to switch back to chair2. No problems back at chair2. Do I just need to call a re-draw function or something? Since it gets 0 draw calls I don’t think it’s just embedded in a mesh. Or am i completely wrong?
Here is the script:
using UnityEngine;
using System.Collections;
public class buttonPusher : MonoBehaviour {
RaycastHit rayhit;
public Collider chair1;
public Collider chair2;
public Camera cam1;
public Camera cam2;
// Use this for initialization
void Start () {
cam1.enabled = true;
cam2.enabled = false;
}
// Update is called once per frame
void Update () {
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
cam1 = this.camera;
if(Input.GetMouseButtonDown(0))
{
Physics.Raycast(ray, out rayhit);
Debug.Log(rayhit.collider);
if (rayhit.collider == chair1)
{
cam1.enabled = true;
cam2.enabled = false;
}
if(rayhit.collider == chair2)
{
cam1.enabled = false;
cam2.enabled = true;
}
}
}
}