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 /
This question was closed Apr 25, 2018 at 11:23 AM by tormentoarmagedoom for the following reason:

The question is answered, right answer was accepted

avatar image
6
Question by moh05 · Dec 29, 2015 at 12:01 PM · guialignmentcardhand

Aligning Cards in Hand Deck

Hello guys!

I am developing a card game similar to Monopoly Deal.

For now, I am trying to implement the hand deck style of Hearthstone.

alt text

As a test, I created a button that adds a card to a specific location in my screen. Below is the button script. When the button is pressed, the FitCard function is called.

 public class orderCards : MonoBehaviour 
 {
     public List <Image> items ; // List that holds all my ten cards
     public Transform start;  //Location where to start adding my cards
     public Transform HandDeck; //The hand panel reference
     public float howManyAdded; // How many cards I added so far
     float gapFromOneItemToTheNextOne; //the gap I need between each card
 
     void Start()
     {
         howManyAdded = 0.0f;
         gapFromOneItemToTheNextOne = 1.0f;
     }
 
     public void FitCards()
     {
 
         if (items.Count == 0) //if list is null, stop function
             return;
 
         Image img = items [0]; //Reference to first image in my list
 
         img.transform.position = start.position; //relocating my card to the Start Position
         img.transform.position += new Vector3 (( howManyAdded*gapFromOneItemToTheNextOne), 0, 0); // Moving my card 1f to the right
         img.transform.SetParent (HandDeck); //Setting ym card parent to be the Hand Panel
 
         items.RemoveAt (0);
         howManyAdded++;
     }
 }

What I get is this so far: alt text

I am just wondering how to implement the curvy alignment. Any help will be much appreciated :)

card-alignment.png (45.4 kB)
hearthstone-handdeck.png (145.6 kB)
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

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by Fattie · Dec 29, 2015 at 03:07 PM

try adding a line

 img.transform.Rotate( 0f, 0f, -6f );

to all the cards.

After you experiment with that, try some code like this ..

 float totalTwist = 20f;
 // 20f for example, try various values
 int numberOfCards = ... get this from your List or array
 float twistPerCard = totalTwist / numberOfCards;
 float startTwist = -1f * (totalTwist / 2f);

where you use howManyAdded , basically do this...

 float twistForThisCard = startTwist +
            (howManyAdded * twistPerCard);
 img.transform.Rotate( 0f, 0f, twistForThisCard);

That should get you going.

Further, note that the cards on each end should sit "down" a bit.

Try adding code like this...

 float scalingFactor = 0.01f;
 // that should be roughly one-tenth the height of one
 // of your cards, just experiment until it works well
 float nudgeThisCard = Mathf.Abs( twistForThisCard);
 nudgeThisCard *= scalingFactor;
 img.transform.Translate( 0f, -nudgeThisCard, 0f );

Have fun!

Now, you can improve you look by slightly randomizing each value, for the twist and the nudge.

This is a good chance for you to...

...learn how to make an extension in c#.

Make a new text file HandyExtensions.cs like this ...

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public static class HandyExtensions
     {
     public static float Jiggled(this float ff)
         {
         return ff * Random.Range(0.9f,1.1f);
         }
     }

As you can see, the Jiggled() extension will take a float and change it slightly. Try it like this

 float x = 3.5f;
 Debug.Log("x is " + x);
 Debug.Log("x is " + x.Jiggled() );
 Debug.Log("x is " + x.Jiggled() );
 Debug.Log("x is " + x.Jiggled() );
 Debug.Log("x is " + x.Jiggled() );
 Debug.Log("x is " + x.Jiggled() );

Do some tests like that until you have a good understanding of extensions.

As you can see it's one of the most powerful language features.

So, where you have these two lines of code

 img.transform.Rotate( 0f, 0f, twistForThisCard);
 img.transform.Translate( 0f, -nudgeThisCard, 0f );

simply change to

 img.transform.Rotate( 0f, 0f, twistForThisCard.Jiggled() );
 img.transform.Translate( 0f, -nudgeThisCard.Jiggled(), 0f );

Hope it gets you started.

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 Astrydax · May 30, 2016 at 10:56 PM 0
Share

Just to clarify, does this line of code have a typo?

  img.transform.Rotate( 0f, 0f, twistForThisCard,Jiggled() ); 

Should be this ins$$anonymous$$d:

 img.transform.Rotate( 0f, 0f, twistForThisCard.Jiggled() );

or was this intended? I'm not very familiar with extensions.

avatar image Fattie Astrydax · May 31, 2016 at 12:48 AM 0
Share

correct, it's a DOT, thanks

avatar image adriandevera Fattie · Mar 11, 2018 at 05:19 PM 0
Share

@Fattie

Like the HandyExtension I could alternatively just make an interface class and have whatever object inherit it as necessary correct? Not sure what a HandyExtension is but is this Unity specific?

Show more comments

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Customize a scripted GUI 1 Answer

Trading card game. Need help scripting the cards. 1 Answer

GUI centering help 1 Answer

Enlarge GameObject in GUI panel when MouseOver 1 Answer

Center Aligned Text Overlaps 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