LoginSignup
2
0

More than 5 years have passed since last update.

Unity カードの移動方法

Last updated at Posted at 2019-04-03
Player.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {
    public Hand hand;
    public Field field;

    public void PushSettingCardOnFieldFromHand(){
        Card card = hand.Pull(0);
        field.Add(card);        
    }
}
Field.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Field : MonoBehaviour {
    public List<Card> cardList = new List<Card>();
    public void Add(Card _card){
        _card.transform.SetParent(this.transform);
        cardList.Add(_card);
    }
    public Card Pull(int _position){
        Card card = cardList[_position];
        cardList.Remove(card);
        return card;
    }
}

Hand.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hand : MonoBehaviour {
    public GameObject cardPrefab;
    public List<Card> cardList = new List<Card>();

    void Awake () {
        for(int i=0; i<5 ; i++){
            GameObject cardObj = Instantiate(cardPrefab);
            Card card = cardObj.GetComponent<Card>();
            this.Add(card);
        }
    }
    void Add(Card _card){
        _card.transform.SetParent(this.transform);
        cardList.Add(_card);
    }
    public Card Pull(int _position){
        Card card = cardList[_position];
        cardList.Remove(card);
        return card;
    }
}
Card.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Card : MonoBehaviour { 
}

スタジオしまづでゲームの作り方を学びたい人向けのサロン▶︎https://camp-fire.jp/projects/view/149191

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0