Skip to content

Instantly share code, notes, and snippets.

@gremito
Created February 9, 2020 03:18
Show Gist options
  • Save gremito/564e5dff3b5c98deaa80315c04e9c494 to your computer and use it in GitHub Desktop.
Save gremito/564e5dff3b5c98deaa80315c04e9c494 to your computer and use it in GitHub Desktop.
Dealer.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dealer : MonoBehaviour
{
/// <summary>
/// カードの種類とカードのGameObjectを一緒に管理
/// </summary>
Dictionary<int, GameObject> cards;
/// <summary>
/// カードのGameObject(プレハブ)
/// </summary>
[SerializeField]
private List<GameObject> cardPrefabs;
/// <summary>
/// 場に出ているカードのGameObject(クローン)
/// </summary>
private List<GameObject> fieldCards;
void Start()
{
// カード情報の初期化
cards = new Dictionary<int, GameObject>();
cards.Add(0, cardPrefabs[0]);
cards.Add(1, cardPrefabs[1]);
cards.Add(2, cardPrefabs[2]);
cards.Add(3, cardPrefabs[3]);
fieldCards = new List<GameObject>();
// カードを場に出す
foreach(var card in cards)
{
Debug.Log(card.Key);
var go = Instantiate(card.Value);
fieldCards.Add(go);
if(card.Key > 0)
{
go.transform.position = new Vector3(
fieldCards[card.Key-1].transform.position.x + 0.25f,
fieldCards[card.Key-1].transform.position.y,
fieldCards[card.Key-1].transform.position.z
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment