• 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 funnyMonkey · Aug 29, 2012 at 10:40 AM · c#onmousedown

Why is OnMouseDown only working if i click outside of unity then click the object?

I have a script attached to a door object. The door has a mesh collider on it. the script has a the start , FixedUpdate, and OnMouseDown. the start just initilizes some data, the fixedupdate makes the door open or close after its been clicked on and the OnMouseDown sets a boolian saying if it should be open or closed. but for some reason the OnMouseDown only works if i click out side of unity then click on the door. so to open it or close the door i have to click on my taskbar then the door. and thats only in play mode when i build it, it doesnt work at all. I have checked all cameras to make sure that is the main camera. What is causeing this?

 public enum doorUnlockType { key, trigger, unlocked }
 public enum doorOpenStyle { slideUp }
 bool unlocked;
 bool open = false;
 public doorUnlockType unlockType = doorUnlockType.unlocked;
 public doorOpenStyle openStyle = doorOpenStyle.slideUp;
 public float openAmount;
 float start;
 public float openSpeed;

 void Start()
 {
     switch (unlockType)
     {
         case doorUnlockType.unlocked:
             unlocked = true;
             break;
         case doorUnlockType.trigger:
             unlocked = false;
             break;
         case doorUnlockType.key:
             unlocked = false;
             break;
     }
     start = transform.position.y;
 }

 void FixedUpdate()
 {
     if (open)
     {
         switch (openStyle)
         {
             case doorOpenStyle.slideUp:
                 if (transform.position.y < start + openAmount)
                 {
                     transform.position += new Vector3(0, openSpeed, 0);
                 }
                 break;
         }
     }
     else
     {
         switch (openStyle)
         {
             case doorOpenStyle.slideUp:
                 if (transform.position.y > start)
                 {
                     transform.position -= new Vector3(0, openSpeed, 0);
                 }
                 else if(transform.position.y != start)
                     transform.position = new Vector3(transform.position.x,start,transform.position.z);
                 break;
         }
     }
 }

 void OnMouseDown()
 {
     Debug.Log("click");
     if (unlocked)
     {
         open = !open;
     }
 }
 
Comment
Add comment · Show 4
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 Piflik · Aug 29, 2012 at 10:55 AM 0
Share

Please add the script. I have an idea what might be wrong, but without the script it is impossible to say, if I have the right idea.

avatar image funnyMonkey · Aug 29, 2012 at 03:48 PM 0
Share

Post Updated with Code

avatar image MathieuBarbier · Aug 29, 2012 at 03:57 PM 0
Share

Do you have any collider beetween the camera and the door ?

avatar image funnyMonkey · Aug 29, 2012 at 04:02 PM 0
Share

No only the collider on the door i checked Also if I ray cant from the camera to the door it will work witch is why i thought maybe another camera has input but i checked all the depths and no camera other camera should be cause problems, only cameras are the cameras that get created for the water and a $$anonymous$$i map camera

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Looping and closing walls 1 Answer

OnMouseDown Firing When I Miss 2DCollider 0 Answers

Can I use OnMouseDown for touch input? C# Nexus 2 Answers


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