Hello I’m trying to create a GUI using 3D objects in front of my second Camera(GUI Cam).
I’m using Raycast to determine which object I’m clicking on but I keep getting this Error.
MissingComponentException: There is no ‘Collider’ attached to the “Camera” game object, but a script is trying to access it.
You probably need to add a Collider to the game object “Camera”. Or your script needs to check if the component is attached before using it.
Camera is located away from my scene, and I’m using a script that is supposed to cast a raycast from that camera.
using UnityEngine;
using System.Collections;
public class RaycastGUI : MonoBehaviour
{
public Camera camToUse;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1"))
{
Ray ray;
RaycastHit hit;
ray = camToUse.ScreenPointToRay(Input.mousePosition);
if (collider.Raycast(ray, out hit, 100.0f))
{
Debug.Log(hit.transform.name);
}
}
}
}
Anyone can pinpoint the problem ?