Hi. I have a prefab of a textured cube (supposed to be a metal plate) and it has some scripts attached to it. One disables the camera orbit script (which is in a different gameobject) when the mouse is over it, and one allows it to be dragged. The reason the camera orbit is disabled when the mouse is over it is because when the player drags it, the camera moves too. It works with the original cube that is already in the scene, but the prefab won’t accept the camera as a variable, giving me this error:
UnassignedReferenceException: The variable mouseOrbitScript of ‘disableMouseOrbit’ has not been assigned.
You probably need to assign the mouseOrbitScript variable of the disableMouseOrbit script in the inspector.
disableMouseOrbit.OnMouseUp () (at Assets/disableMouseOrbit.js:9)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
Here is my code:
var mouseOrbitScript : GameObject = GameObject.FindWithTag("MainCamera");
function OnMouseOver () {
if(Input.GetKeyDown(KeyCode.Mouse0)){
mouseOrbitScript.GetComponent(MouseOrbit).enabled = false;
}
}
function OnMouseUp(){
mouseOrbitScript.GetComponent(MouseOrbit).enabled = true;
}