• 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
Question by DaniDiaz · Jun 05, 2016 at 04:14 PM · rotationrigidbody2dcollider2dcollision2dtetris

Disable click action when collision

I have a 2D block falling (like tetris) and is rotating when click on this. I would to disabled this action (rotation when click) when the blocks do collision with the ground. I try this but I don´t know why but it isn´t work. The rotation work but it doesn´t stop This is the script to stop the rotation:

var rotar = rotaralclick;

 function OnTriggerEnter(Otro : Collider)
 {
     if (Otro.gameObject.name == "suelo") 
     {
         GetComponent.rotar.enabled=false;
     }
 }


and this is the script of the rotation, in the same prefab

 function Update ()
 {
     if(Input.GetMouseButtonDown(0))
         transform.Rotate(0, 0, -90);
 }
 
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by ownerfate · Jun 06, 2016 at 11:42 PM

for your Bottom script, add the variable: var hasLanded = false;

this is what it should look like in the top Script:

  function OnTriggerEnter(Otro : Collider)
  {
      if (Otro.gameObject.name == "suelo") 
      {
          GetComponent.rotar.enabled=false;
         this.GetComponent( bottom Script name Goes here ).hasLanded = true;
      }
  }


and the bottom Script should look like this:

 var hasLanded = false;
 
  function Update ()
  {
 if(hasLanded == false)
 {
      if(Input.GetMouseButtonDown(0))
          transform.Rotate(0, 0, -90);
  }
 }


if i am reading what you're saying, and both scripts are indeed on the same object, this will work.

hope this helps.

Comment
DaniDiaz

People who like this

1 Show 2 · 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 DaniDiaz · Jun 10, 2016 at 05:25 PM 0
Share

Thank ownerfate, the botton script work perfectly, but the second script didn´t work well, I change ontriggerenter and I wrote Oncollisionenter2D and it´s fine. Probably it was only a problem of my scene.

avatar image ownerfate DaniDiaz · Jun 11, 2016 at 01:07 AM 0
Share

anytime, and yeah, it might had been, then again, maybe not, that's the wonders of programming, ha ha

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

making a mushroom trampoline , bouncing the gameobject relative to mushroom's rotation 1 Answer

Workarounds for Higher Control When Using Physics2D? 0 Answers

[SOLVED] How to Destroy a rigidbody game object on collision with another gameobject? 4 Answers

HOW TO CALLBACK COLLIDER WITH NAME? 2 Answers

multiple objects on oncollissionstay2d 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