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 math_lab · Apr 23, 2019 at 02:03 AM · scripting problempositionpositioningcard

Need help for a Card Game! How to place the cards at the right spot?

I want to know how or what should I do to be able that my cards goes to the right spot. Here's a screenshot of my problem, I want them to go in the rectangles. alt text

I guess I need to add some stuff to my script. Here are my two main scripts(I didn't wrote them myself I was following a tutorial): 1-

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GameController : MonoBehaviour
 {
 
     public CardStack player;
     public CardStack dealer1;
     public CardStack dealer2;
     public CardStack dealer3;
     public CardStack deck;
 
           
     void Start()
     {
           PlayCards();
     }
 
     private void Update()
     {
              
     }
 
     public void PlayCards()
     {
         for (int i = 0; i < 8; i++)
         {
             player.Push(deck.Pop());
             dealer1.Push(deck.Pop());
             dealer2.Push(deck.Pop());
             dealer3.Push(deck.Pop());
 
         }
 
     }
 
 }

2-

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 
 [RequireComponent(typeof(CardStack))]
 public class CardStackView : MonoBehaviour
 {
     CardStack deck;
     Dictionary<int, CardView> fetchedCards;     //Show FaceUp
     int lastCount;
 
     
     public Vector3 start;
     public float cardOffset;
     public bool faceUp = false;     //Show FaceUp
     public bool reverseLayerOrder = false;  //Cards being remove from the top of the deck
     public GameObject cardPrefab;
 
 
     public CardStack player;                
     public CardStack dealer1;
     public CardStack dealer2;
     public CardStack dealer3;
     
     public void Toggle(int card, bool isFaceUp) //Show FaceUp
     {
         fetchedCards[card].IsFaceUp = isFaceUp;
     }
 
     private void Start()
     {
         fetchedCards = new Dictionary<int, CardView>();
         deck = GetComponent<CardStack>();
         ShowCards();
         lastCount = deck.CardCount;
 
         deck.CardRemoved += deck_CardRemoved;
 
               
 
     }
 
     private void deck_CardRemoved(object sender, CardRemovedEventArgs e)
     {
         if (fetchedCards.ContainsKey(e.CardIndex))
         {
             Destroy(fetchedCards[e.CardIndex].Card);
             fetchedCards.Remove(e.CardIndex);
         }
     }
 
     private void Update()
     {
         if (lastCount != deck.CardCount)
         {
             lastCount = deck.CardCount;
             ShowCards();
         }
     }
 
     void ShowCards()
     {
         int cardCount = 0;
 
         if (deck.HasCards)
         {
 
 
             foreach (int i in deck.GetCards())
             {
                 float co = cardOffset * cardCount;
                 Vector3 temp = start + new Vector3(co, 0f);
                 AddCard(temp, i, cardCount);
                 cardCount++;
 
             }
         }
     }
 
     void AddCard(Vector3 position, int cardIndex, int positionalIndex)
     {
        
         if (fetchedCards.ContainsKey(cardIndex))
         {
             if (!faceUp)        //Show FaceUp
             {
                 CardModel model = fetchedCards[cardIndex].Card.GetComponent<CardModel>();
                 model.ToggleFace(fetchedCards[cardIndex].IsFaceUp);
                 
 
             }
             return;
         }
 
            
 
         GameObject cardCopy = (GameObject)Instantiate(cardPrefab);
         cardCopy.transform.position = position;
 
         CardModel cardModel = cardCopy.GetComponent<CardModel>();
         cardModel.cardIndex = cardIndex;
         cardModel.ToggleFace(faceUp);
 
         SpriteRenderer spriterenderer = cardCopy.GetComponent<SpriteRenderer>();
         if (reverseLayerOrder)  //Cards being removed from the top of the deck \/
         {
             spriterenderer.sortingOrder = 51 - 1 - positionalIndex;
         }
         else
         {
             spriterenderer.sortingOrder = positionalIndex;
         }  //   /\
 
 
         fetchedCards.Add(cardIndex, new CardView(cardCopy));
 
         Debug.Log("Hand value = " + deck.HandValue());
 
     }
 
  
 }
 

Thanks!! Really want to finish that first project!

cardproject.png (167.2 kB)
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 mansoor090 · Apr 23, 2019 at 06:09 AM 0
Share

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

@math_lab hope this will help. i haven't work on cards yet

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.

Follow this Question

Answers Answers and Comments

191 People are following this question.

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

Related Questions

Why Do My Obstacles Do This In My Object Pooler? 1 Answer

How to increment value of axis when something happens 2 Answers

UI image position assignment not working correctly 1 Answer

AR Object stuck in front of camera 0 Answers

Clamping local movement 0 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