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
1
Question by Hotuta · Jul 01, 2014 at 11:37 PM · c#gameobjectrotatememoryonmousedown

Rotate Object 180º OnClick

Hello, Im having a little trouble im making a Memory Match Game. Im new at Unity and C# and I dont know how to make this script.

When the player click on the object (card) it should rotate 180º to see the otherside.

Someone can help me with this?

Comment
Add comment · Show 1
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 christoph_r · Jul 01, 2014 at 11:44 PM 0
Share

So, where exactly is the issue? The more precisely you formulate your question, the better we can help you. Are you having trouble with the rotation part, checking when the player clicked on a card etc. etc.

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by NikunjPopat · Jul 02, 2014 at 02:09 PM

Apply code snippet to GameObject

 //C#
 void OnMouseDown(){
         transform.Rotate(0,0,180);
 }
 
 //java script
 
 function OnMouseDown(){
         transform.Rotate(0,0,180);
 }

Comment
Add comment · 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
0

Answer by Hikaros · Jul 01, 2014 at 11:45 PM

There are two options (that i know of)

  void OnMouseDown(){
         transform.rotation = Quaternion.Euler(0,0, -90);
     }

and

 void Update() {
         if (Input.GetMouseButtonDown(0)){
             RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
             
             if(hit){
                 transform.rotation = Quaternion.Euler(0,0, -90);
             }
         }
     }

-90 rotates to the right, 90 to the left.

EDIT:

i re read question lol, i thought u wanted to rotate it sideways. do you want to flip it?

If that is the case i don't think you can do that with a 2d sprite (because it is the same back and front so if you "rotated" it 180 degs you'd have the same image but mirrowed), however you can change sprites (one being front and one being the back of it). To change the sprite should be something like:

 public SpriteRenderer jackRenderer;
     public Sprite backOfCard;
 
 void OnMouseDown(){
         GetComponent<SpriteRenderer>().sprite = backOfCard;        
     }
 
Comment
Add comment · 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
0

Answer by YoungDeveloper · Jul 01, 2014 at 11:46 PM

Unity has great tutorials related to rotation and movement.

https://www.youtube.com/watch?v=TdjoQB43EsQ

https://www.youtube.com/watch?v=Ywn7n0SXB4M

Comment
Add comment · Show 3 · 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 Hikaros · Jul 01, 2014 at 11:55 PM 0
Share

i think he wants to flip it to show the front/back of a card but in 2D (if i'm not wrong) if you "rotate" the card 180 degrees you will have the same image but mirrowed haha so changing the sprite should be the way to go or so i think x_x

avatar image YoungDeveloper · Jul 02, 2014 at 12:25 AM 0
Share

Dont know, he never mentioned nothing about 2D though.

avatar image Hikaros · Jul 02, 2014 at 07:43 PM 0
Share

lol you are right, i completely assumed that myself hahaha it is just so weird to see a 3D card game (at least in my case) so i assumed it, my bad o:

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Reference creator of gameObject 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

How can I move a player toward a gameobject by clickling an image 0 Answers

Rotate gameobject on Y axis 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