using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//玩家手里卡牌的获得后的刷新和出牌后的刷新
public class Mycards : MonoBehaviour {
public Transform card01;//意图表示第一张牌的位置
public Transform card02;
public GameObject cardsprefab;
private float thedistance;//两张牌的距离
private List<GameObject> cards = new List<GameObject>();
void Start()
{
thedistance = card02.position.x - card01.position.x;//两张牌的距离
}
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
Getcard();
}
if (Input.GetKeyDown(KeyCode.W))
{
losecard();
}
}
//获得卡牌即摸牌
public void Getcard()
{
GameObject go = NGUITools.AddChild(this.gameObject, cardsprefab);//this .gameObject指的就是当前要把脚本的绑定到物体,把这个物体赋值给物体go
Vector3 toposition = card01.position + new Vector3(thedistance, 0, 0) * cards.Count;//获得卡牌到达的位置,(现有牌数量的最后面,即与第一张牌的距离位置)
iTween.MoveTo(go, toposition, 1f);//移动物体go到指定位置即toposition
cards.Add(go);
}
//移除卡牌即出牌
public void losecard()
{
int indexd = Random.Range(0, cards.Count);//随机打出手中某一张牌
Destroy(cards[indexd]);
cards.RemoveAt(indexd);
for (int i = 0; i < cards.Count; i++)//移除后刷新手中所有牌的位置
{
Vector3 toposition = card01.position + new Vector3(thedistance, 0, 0) * i ;//第i张牌的位置(即与第一张牌的距离)
iTween.MoveTo(cards[i], toposition, 0.5f);//刷新与第一张牌的距离(即刷新手中所有牌的位置)
}
}
}
unity开发炉石传说系列玩家手中卡牌出入及移动排列代码
最新推荐文章于 2025-06-16 09:34:01 发布