Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Teapot-C · Oct 01, 2013 at 10:53 AM · cameraguipause

How to deactivate a script temporarly on another object when clicking a GUI ?

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.
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hamstar · Oct 01, 2013 at 11:39 AM

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;
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Teapot-C · Oct 01, 2013 at 12:28 PM 0
Share

Yay thanks, i renamed my camera and it works. But the feature "$$anonymous$$ouseOrbit_onclick" stays deactivated after that... I tried to add an On$$anonymous$$ouseUp function but now it still gets activated.

 function On$$anonymous$$ouseUp(){
     GameObject.Find("ObjectCamera").GetComponent("$$anonymous$$ouseOrbitZoom").enabled = true;
 }

 

I tried with "if" and "else" but doesn't work.

 function On$$anonymous$$ouseDown () {
     var camera : $$anonymous$$ouseOrbit_onclick = gameObject.Find("ObjectCamera").GetComponent($$anonymous$$ouseOrbitZoom);  
     if (Input.Get$$anonymous$$ouseButton(0)){
     camera.enabled = false;
     }    
 
 }

What is the reverse function to use there ? Thanks a lot :)

avatar image hamstar · Oct 01, 2013 at 12:36 PM 0
Share

That's almost there. But you need GameObject.Find. With gameObject.Find you are just searching on the gameObject the script it attached to.

 function On$$anonymous$$ouseDown() {
         GameObject.Find("ObjectCamera").GetComponent($$anonymous$$ouseOrbitZoom).enabled = false;
     }    
 function On$$anonymous$$ouseUp() {
         GameObject.Find("ObjectCamera").GetComponent($$anonymous$$ouseOrbitZoom).enabled = true;
     }
avatar image Teapot-C · Oct 01, 2013 at 12:54 PM 0
Share

Thanks a lot ! That works, i just have to put that script on the good Gui now...

thanks again hamstar :)

avatar image hamstar · Oct 01, 2013 at 01:06 PM 0
Share

Good, no problem!

avatar image
0

Answer by Teapot-C · Oct 01, 2013 at 01:29 PM

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 ?

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hamstar · Oct 01, 2013 at 02:12 PM 0
Share

A screenshot of what you're doing might be useful. Perhaps you can use GUIUtility.hotControl in your $$anonymous$$ouseOrbitZoom scripts. Enclose all your logic in an if like:

 if(GUIUtility.hotControl == 0) {
   // check user input and do Orbit/Zoom
 }


avatar image Teapot-C · Oct 01, 2013 at 02:47 PM 0
Share

Alright here is a screenshot.

alt text

The camera turns around the sofa when left click & drag. Also the camera zooms in/out when clic&drag right button.

With the script explained in this post, when clicking on the dark area or the tumbnails, the camera doesn't move.

The white square is the slider thumb and shows which material is selected and applied on the sofa (can be changed by dragging horizontally, as seen on clipboard2):

alt text

I've modified my script so that it takes care of both left and right buttons :

 function On$$anonymous$$ouseOver () {
 if (Input.Get$$anonymous$$ouseButtonDown(1)){
     GameObject.Find("ObjectCamera").GetComponent("$$anonymous$$ouseOrbitZoom").enabled = false;
     }
 if (Input.Get$$anonymous$$ouseButtonDown(0)){
     GameObject.Find("ObjectCamera").GetComponent("$$anonymous$$ouseOrbitZoom").enabled = false;
     }
 if (Input.Get$$anonymous$$ouseButtonUp(1)){
     GameObject.Find("ObjectCamera").GetComponent("$$anonymous$$ouseOrbitZoom").enabled = true;
     }
 if (Input.Get$$anonymous$$ouseButtonUp(0)){
     GameObject.Find("ObjectCamera").GetComponent("$$anonymous$$ouseOrbitZoom").enabled = true;
     }
 }
  

I've added this script to each tumbnail, the dark area and the slider. But dragging the slider still rotates the camera around the sofa...

Thanks for helping :)

clipboard02.jpg (14.3 kB)
clipboard01.jpg (15.9 kB)
avatar image Teapot-C · Oct 01, 2013 at 02:52 PM 0
Share

Hm i've looked for that hotcontrol stuff, but i think I can't put my whole $$anonymous$$ouseOrbitZoom scrpit in there... I have some function Update, LateUpdate and a static ClampAngle function. What should I put in the "if(GUIUtility.hotControl == 0) {" section ?

avatar image hamstar · Oct 01, 2013 at 03:44 PM 0
Share

@Teapot-C I posted an idea in my original answer.

avatar image Teapot-C · Oct 02, 2013 at 10:07 AM 0
Share

Thank you a lot hamstar, now it works perfectly ! I tried the opposite, i mean setting the inversed script on an invisible GUItexture over the slider, but it doesn't work (don't really know why, probably a Z coord value). But I'll continue to use that script this way. Thanks again !

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mouse Look Script Pause 3 Answers

A GUI error in script??? HELP,Please!! 1 Answer

How to Hide the GUI when time.scale = 1 again 1 Answer

Transitions When Pausing? 1 Answer

Pause Problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges