Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 missypooh · Jul 26, 2011 at 08:25 AM · scriptingbasics

How to flip the card(in guiTexture)

Hello. I am thinking to create a memory card game. For example, i will have all the cards face down. So when player click on the card, i want the card to flip over. How do i go about doing the effect of flipping the guiTexture?? I hope it is clear. Not good in english.

Thank you

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 missypooh · Jul 27, 2011 at 02:56 PM 0
Share

hello. i don't know how come i can't comment anymore. anyway thank you $$anonymous$$arnix. I will look into it. I have another ideas, don't need to use animation, i think.Something like a close window, so when player click on it, the window are open and the words are displayed? How about this? is it tougher??

http://imageshack.us/photo/my-images/163/images1zuv.jpg/

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Marnix · Jul 26, 2011 at 05:52 PM

As an alternative with GUITextures:

You could animate the GUITexture by scaling it in a horizontal way.

myCard.pixelInset.width = someAnimatedWidth

If the card has a width of 0, swap the texture of the card with the front texture: myCard.texture = theFrontTexture. And then animate it back to its original size.

UPDATE

To animate your card, you should use the Time class. I don't think I can make it any easier for you than this here. It has been written from scratch, so no compilation ensurance. =)

// save the original width in some variable first on the initialize step // set a variable called animateSpeed to some number you like for the speed. // save some state that tells you if we are in the front or in the back. var originalWidth; var animSpeed = 5; var isFront = false; var isAnimating = false; // set this to true when clicking

function Awake() { originalWidth = myCard.pixelInset.width; }

function Update() { if(isAnimating) { if (myCard.pixelInset.width > originalWidth) { // do nothing, the card is as big as it should be newWidth = 0; isAnimating = false; // done animating

         // snap the card to exactly the right size
         myCard.pixelInset.width = originalWidth;
     }
     // check the width of the card
     else if(myCard.pixelInset.width > 0 && !isFront)
     {
         // make smaller, we are still looking at the back
         newWidth = -animSpeed * Time.deltaTime;
     }
     else if(myCard.pixelInset.width > 0 && isFront)
     {
         // make larger, we are looking at the front
         newWidth = animSpeed * Time.deltaTime;
     }
     else if (myCard.pixelInset.width < 0)
     {
         // the turnover point
         myCard.texture = frontTexture;
         isFront = true;
     }            

     // add the new width to the current width
     myCard.pixelInset.width += newWidth;
 }   

}

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 missypooh · Jul 26, 2011 at 06:12 PM 0
Share

hello marnix, thank for the reply. what you mean by someAnimatedWidth?? how to calculate it?? and when will the card's width turn 0?? sorry am not very strong in program$$anonymous$$g.

avatar image Marnix · Jul 27, 2011 at 07:59 AM 0
Share

Updated my answer. I hope this will be enough to understand. I am not saying that this is your correct solution, because I actually agree with @Christian.

avatar image Marnix · Jul 27, 2011 at 04:44 PM 0
Share

If you dont want the animation, you can just change myCard.texture to the front-texture and then you're done.

avatar image missypooh · Jul 28, 2011 at 12:12 PM 0
Share

hello marnix, thank you. i will give it a try although i still quite confused how thing work .

avatar image
0

Answer by CHPedersen · Jul 26, 2011 at 09:08 AM

First of all, I like your idea, this is a great idea for a first game, if you're just starting out with Unity. :)

Secondly, you'll find that this is totally simple if you don't use guitextures for the cards. Make the cards actual 3D objects instead and scale the mesh to give it a proper size as a card. You should use a Cube mesh and make it really thin for a card, not a Plane mesh. This is because a Plane mesh is a single, 2D-surface, and will not accept a different texture on either side. A thin cube will. Then slap the card-textures onto the cubes' front and back. You can use a large plane underneath them all and give it a wooden texture to make it look like the surface of a tabletop, then position a camera right on top of the table and have it look directly down.

Once your cards are 3D objects, you can flip them by rotating them around one of its axes, but remember to do this in LOCAL space. You can use transform.Rotate to accomplish that, making sure you pass Space.Self to indicate local space:

     transform.Rotate(new Vector3(0, 180, 0), Space.Self);

That line of code flips a card to its backside around the y-axis.

Comment
Add comment · Show 10 · 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 missypooh · Jul 26, 2011 at 11:42 AM 0
Share

hello, thank you for the reply. But sorry i totally don't understand what you mean. Care to explain in details?

avatar image CHPedersen · Jul 26, 2011 at 11:57 AM 0
Share

Explain in details what you've done yourself, first. How are your cards modelled currently? Are you using GUITextures, like in this link?

http://unity3d.com/support/documentation/Components/class-GuiTexture.html

avatar image missypooh · Jul 26, 2011 at 12:18 PM 0
Share

hello.. refer to the image http://imageshack.us/photo/my-images/840/memoryd.png/.

So far i only create guiTexture on the wall. Hiding behind is all the words.

avatar image Chris D · Jul 26, 2011 at 04:23 PM 0
Share

If you're just using guiTextures, when a click is detected on a texture, hide that texture to expose the words underneath.

If, as you've mentioned above, you want to have a "flip" effect, you'll have to either animate it with textures (swapping out the texture frame-by-frame to mimic actual movement) or do as Christian said and move to a gameObject-based approach. Of these options, the latter seems like the easier.

avatar image missypooh · Jul 26, 2011 at 04:58 PM 0
Share

hello ChrisD, yes, i agree that the answer Christian suggest is much more easier approach. I try the way and i wonder how come the image i add into cube look so dark. I mean like cannot see properly the texture of the cube.

Show more comments

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What's the difference between a struct and a class? 1 Answer

Script to teleport player (Beginner here) 0 Answers

How to learn scripting without Unity 3 Answers

How to smooth between values? 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