- Home /
Secoundary/GUI camera not pausing/disabeling.
I need to Disable one script on two objects from a script on a third object.
I have a Script on my main camera and on a GUI camera that makes them mimics the movement in the main window (like a Maya or Unitys main view and view cube). My script disables the camera in the main view when I want but the mini-map view cube keeps moving.
Here is a summery of what I have:
private float waitTime = 0.75f; //wait time befor reacting to mouse hold
private float downTime; //internal time from when the key is pressed
private bool isHandled = false; //toggle the mouse hold event on and off
GameObject Cam1;
GameObject Cam2;
FreeObjectRotationCam frc1;
FreeObjectRotationCam frc2;
//link the cameras and movment script for mark up menue pauseing.
void Awake(){
Cam1 = GameObject.Find("Main Camera");
Cam2 = GameObject.Find("GUICamera");
frc1 = Cam1.GetComponent<FreeObjectRotationCam>() as FreeObjectRotationCam;
frc2 = Cam2.GetComponent<FreeObjectRotationCam>() as FreeObjectRotationCam;
}
Then when I hold the mouse down I disable the script.
void OnMouseDrag(){
if((Time.time > downTime + waitTime) && !isHandled){
isHandled = true;// reset the timer for the next button press
//Disable the Camera mouse movement.
frc1.enabled=false;
frc2.enabled=false;
}
The frc1.enabled = true/false works fine but the frc2 is doing nothing. Any ideas how I can make the script turn off on both cameras? I tried frc1.enabled = !frc1.enabled to toggle but that didn't work.
My code is based on the answer here: http://answers.unity3d.com/questions/553324/problem-in-calling-scripts.html
Can I not call the same script twice even though it is on a different object?
When I turn off frc2 first it pauses the view cube and not the main window.
If this question needs any clarification let me know and I will edit as needed.
Answer by Giantbean · Jan 06, 2014 at 05:25 PM
I got the code working. The above code is fine.
I had
//re-enable Camera mouse movement.
void LateUpdate(){
if (Input.GetMouseButtonDown(0)&& isHandled)
frc1.enabled=true;
frc2.enabled=true;
}
which I replaced with
void OnMouseUp(){
frc1.enabled=true;
frc2.enabled=true;
}
and now it is working.
I think I may have had something commented out that shouldn't have been or some syntax error that mono develop didn't catch.
But its working now so its all good. I hope this post helps someone else in need.