Hi,
I’ve got 2 cameras : one (called ObjectCamera) is looking at an object (with Camera_Orbit when clicking), sending the view in a RenderTexture, the second (MainCamera) sees GUI features and the RenderTexture.
When clicking on the GUI and moveing the mouse, the ObjectCamera turns around the object.
How could I disable the rotation when clicking on the GUI objects ?
Here’s the code I tested, but during the test it says
NullReferenceException
UnityEngine.GameObject.GetComponent (System.String type) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:34)
RotationDeactivate.OnMouseDown () (at Assets/Demo Fly/Scripts/RotationDeactivate.js:2)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
function OnMouseDown(){
GameObject.Find("ObjectCamera").GetComponent("MouseOrbit_onclick").enabled = false;
}
Any idea ?
Thanks a lot.
It either can’t find the GameObject named “ObjectCamera”, or the camera does not have a script attached to it called “MouseOrbit_onclick”. Check that the camera name and script name match what you wrote exactly.
Also, just check you aren’t mixing up the object’s name with it’s tag.
Alternative if you want to give ObjectCamera a tag and use that:
GameObject.FindWithTag("ObjectCamera").GetComponent("MouseOrbit_onclick").enabled = false;
[edit]
In response to your 2nd issue (see below).
I’m not sure this is the best solution, but might be worth a try. Create an empty object and give it a GUITexture component. Position and size the gui texture to fit your “window” (sofa view), then give the GUITexture a transparent texture.
Then add a new script like this to the new object:
public var objectCamera : Transform;
private var orbitZoomScript : MouseOrbitZoom;
function Start () {
orbitZoomScript = objectCamera.GetComponent(MouseOrbitZoom);
}
function OnMouseEnter() {
orbitZoomScript.enabled = true;
}
function OnMouseExit() {
orbitZoomScript.enabled = false;
}
Erf, I finally have another issue with that script…
When added onto a GUITexture, it works fine. But when added onto a slider, it doesn’t ; sliding the thumb makes the camera rotate.
I’ve tried to change the depth but no way.
Where do I need to put this script to block the rotation when using the slider too ?