unity3d-学习笔记22-卡牌游戏制作
实现桌面显示打出的卡信息
思路
先在桌面创建一个专门放打出的卡信息的panel
然后在cardController类的onenddrag方法里添加创建卡信息文字text的方法,父类为前面创建的panel即可
设置一下不同卡显示的效果即可,里面的font,fontsize等,直接修改即可
代码
private void ShowCardInHistory()
{
GameObject text = new GameObject();
if(cardType=="1")
{
text.AddComponent<Text>().text = CardDesktop.cardUsedNum + " " + cardName + " 恢复了自身" + cardDemage + "点生命值!";
text.GetComponent<Text>().color = Color.green;
}
if(cardType == "0")
{
text.AddComponent<Text>().text = CardDesktop.cardUsedNum + " " + cardName + " 对敌人造成了" + cardDemage + "点伤害!";
text.GetComponent<Text>().color = new Color(255/255f,0 / 255f, 0 / 255f, 255 / 255f);
}
if (cardType == "2")
{
text.AddComponent<Text>().text = CardDesktop.cardUsedNum + " " + cardName + " 每回合对敌人造成" + cardDemage + "点伤害!";
text.GetComponent<Text>().color = new Color(110 / 255f, 0 / 255f, 144 / 255f, 255 / 255f);
}
if (cardType == "3")
{
text.AddComponent<Text>().text = CardDesktop.cardUsedNum + " " + cardName + " 增加场上攻击卡" + cardDemage + "点伤害!";
text.GetComponent<Text>().color = new Color(219 / 255f, 207 / 255f, 0 / 255f, 255 / 255f);
}
text.AddComponent<ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
text.GetComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
text.GetComponent<Text>().font = Font.CreateDynamicFontFromOSFont("Arial",50);
text.GetComponent<Text>().fontSize = 50;
text.GetComponent<Text>().fontStyle = FontStyle.Bold;
text.transform.SetParent(GameObject.Find("historyInfo").transform,false);
text.transform.localScale = new Vector3(text.transform.localScale.x*0.79f, text.transform.localScale.y*0.83f);
CardDesktop.cardUsedNum++;
}
打出毒卡显示图标和文字
思路
在桌面给boss创建一个放boss的buff的panel,当cardController类打出卡的时候判断为毒卡时,在这个创建的panel里动态创建一个gameobject,并用addcomponent方法将毒buff的图标动态加载进去即可
文字是同样的套路,先创建显示文字的panel区域,然后跟前面一样即可
代码
明天再贴
这里我还优化了一下,在每个卡的最前面添加了一个id,显示是第一张打出的卡,这个需要在桌面类创建一个静态的变量,每次打出的时候++即可
添加战斗结束的判定和界面——————完成
把战斗的界面统一到所有需要战斗的事件里——————完成
添加除战斗界面的其他事件界面
boss简单的攻击模式(也要能打出卡的)
ui,原画等精细优化
画面一侧要有出牌的记录——————完成
人物的buff图标————————完成毒卡的buff显示
能量卡的消耗需要可视化———————完成