记录在自学unity的过程中实现的小功能。
大体功能是第一次点击高亮标记卡牌,第二次点击出牌,右键取消选择。
单击方法用的是NGUI自带的单击。
实现方法就是把这三个脚本挂上就行了。
private bool firstClicked = false;
private bool secondClicked = false;
private string CardName;
public CardEffect cardEffect;
public Card card;
public Transform CManager;
public Vector3 CardPosition;
public GameObject CardGO;
public void OnDoubleClicked() //双击出牌
{
if (firstClicked == false)
{
firstClicked = true;
//第一次点击高亮
//实现高亮的代码
Debug.Log("firstclicked");
}
else if(secondClicked == false) //双击后的功能实现
{
if (GameObject.Find("Manager").GetComponent<FightManager>().Turn == FightManager.TurnState.PlayerTurn)//如果是你的回合
{
//出牌
//Debug.Log("chupai");
SetCard(); //获取点击的牌
//Debug.Log(CardName);
//Debug.Log(card);
if (GameObject.Find("Manager").GetComponent<PlayerManager>().NowCost >= card.Cost)//费用计算
{
SendMessage(CardName, this.gameObject, SendMessageOptions.RequireReceiver);//运行对应方法
firstClicked = false;
Destroy(this.gameObject);//删除卡牌
GameObject.Find("Manager").GetComponent<PlayerManager>().NowCost = GameObject.Find("Manager").GetComponent<PlayerManager>().NowCost - card.Cost; //计算出牌后剩余费用
}
else
{
Debug.Log("行动点不够!");
firstClicked = false;
}
}
else
Debug.Log("不是你的回合!");
}
else
{
Debug.Log(firstClicked);
Debug.Log(secondClicked);
}
}
public void OnRightClicked() //右键点击取消选中
{
if(Input.GetMouseButtonDown(1))
firstClicked = false;
//取消高亮代码
}
public void SetCard() //获取点击的卡牌信息
{
CardName = this.transform.Find("cardname/name").GetComponent<UILabel>().text;
card = this.transform.GetComponent<CardInstance>().card;
CardPosition = this.transform.position;
CardGO = this.gameObject;
}