Hi, I have a static camera using a modified MouseOrbit script to orbit around and view my whole custom skybox, I have set up the raycasting and I get a result with OnMouseDown which is perfect, I also have a separate material array script that I have tried to incorporate into my RayCast script but to no avail, I keep getting this error message:
“MissingComponentException: There is no ‘Renderer’ attached to the “Main Camera” game object, but a script is trying to access it.
You probably need to add a Renderer to the game object “Main Camera”. Or your script needs to check if the component is attached before using it.
RayCast Button.Update () (at Assets/RayCast Button.js:17)”
What am I doing wrong?
I’m trying to click on a plane/gameobject in the 3d space that will change/array through my different sky box materials.
Can anybody help me fix my script? I have attached it below, I feel I’m so close to getting the desired result!
Thank you.
var clickable : GameObject;
var matArray : Material[];
private var index : int;
function Update () {
if (Input.GetButtonDown ("Fire1")) {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
index++;
index = index % matArray.Length;
renderer.material = matArray[index];
}}}