Okay I’m a complete scripting noob so my attempt at this is a bit rubbish at the minute and I could use some help.
I have a ray projecting from my camera. I want to point it at an object and then left click on that object to cycle through its material array. So far I have this (copied and pasted from other scripts so I dont really know what I’m doing). I can’t get it to work. Where am I going wrong?
private var index : int;
var e : Event = Event.current;
function Update () {
// Project a ray going through the center of the screen
public var ray : Ray = camera.ViewportPointToRay (Vector3(0.5,0.5,0));
// If a ray hits an object, and the user pressess the LMB, cycle through the objects' Material array
if (Physics.Raycast (ray, hit)) {
if(e.button == 0 && e.isMouse){
Debug.Log("Left Click");
index++;
index = index % matArray.Length;
renderer.material = matArray[index];
}
}
}