Unity实现杀戮尖塔出牌效果(一.扇形开牌)
创始人
2024-12-16 07:07:00
0

最终效果展示

主要步骤

一. 扇形开牌

二. 鼠标指向卡牌时,卡牌强调动画

①卡牌高度提升
②卡牌旋转归零
③卡牌层级高于其他手牌

三. 卡牌使用效果

1. 攻击类型卡牌

①拖拽超过一定高度之后卡牌会移动到手牌中心位置
②出现攻击引导箭头
③成功指向目标怪物后打出

2. 技能能力类型卡牌

①可自由拖动
②脱离手牌高度后打出

四. 卡牌使用结束效果

1. 播放攻击特效

2. 播放卡牌收尾特效

①卡牌从当前位置移动到中心位置
②卡牌居中悬停展示几毫秒
③播放回归弃牌堆动画

代码详解

一. 扇形开牌

在这里插入图片描述

核心代码

public class CardItem : MonoBehaviour   {       ///        /// 卡牌扇形展开中心点       ///        public Vector3 root;       ///        /// 展开角度       ///        public float rot;       ///        /// 展开半径       ///        public float size;       ///        /// 动画速度       ///        public float animSpeed = 10;       ///        /// 高度值(决定卡牌层级)       ///        public float zPos=0;             public  void RefreshData(Vector3 root,float rot, float size,float zPos)       {                 this.root = root;           this.rot = rot;           this.size = size;           this.zPos = -zPos*0.02f;       }       // Update is called once per frame       void Update()       {                 SetPos();       }       public void SetPos()       {                 //设置卡牌位置           float x = root.x + Mathf.Cos(rot) * size;           float y = root.y + Mathf.Sin(rot) * size;           transform.position = Vector3.Lerp(transform.position, new Vector3(x, y, root.z+this.zPos), Time.deltaTime * animSpeed);           //设置卡牌角度           float rotZ = GetAngleInDegrees(root, transform.position);           Vector3 localEulerAngles = transform.localEulerAngles;           Quaternion rotationQuaternion = Quaternion.Euler(new Vector3(0, 0, rotZ));           transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationQuaternion, Time.deltaTime * animSpeed * 30);       }         ///        /// 获取两个向量之间的弧度值0-2π       ///     /// 点A坐标       /// 点B坐标       ///          public static float GetAngleInDegrees(Vector3 positionA, Vector3 positionB)       {                 // 计算从A指向B的向量           Vector3 direction = positionB - positionA;           // 将向量标准化           Vector3 normalizedDirection = direction.normalized;           // 计算夹角的弧度值           float dotProduct = Vector3.Dot(normalizedDirection, Vector3.up);           float angleInRadians = Mathf.Acos(dotProduct);              //判断夹角的方向:通过计算一个参考向量与两个物体之间的叉乘,可以确定夹角是顺时针还是逆时针方向。这将帮助我们将夹角的范围扩展到0到360度。           Vector3 cross = Vector3.Cross(normalizedDirection, Vector3.up);           if (cross.z > 0)           {                        angleInRadians = 2 * Mathf.PI - angleInRadians;           }           // 将弧度值转换为角度值           float angleInDegrees = angleInRadians * Mathf.Rad2Deg;           return angleInDegrees;       }} 
public class CardManager : MonoBehaviour   {       ///        /// 卡牌起始位置       ///        public Vector3 rootPos=new Vector3(0,-33.5f,20);       ///        /// 卡牌对象       ///        public GameObject cardItem;       ///        /// 扇形半径       ///        public float size =30f;       ///        /// 卡牌出现最大位置       ///        private float minPos = 1.415f;       ///        /// 卡牌出现最小位置       ///        private float maxPos = 1.73f;       ///        /// 手牌列表       ///        private List cardList;       ///        /// 手牌位置       ///        private List rotPos;       ///        /// 最大手牌数量       ///        private int CardMaxCount=8;          void Start()       {        InitCard();       }    ///        /// 数据初始化       ///        public  void InitCard()       {             rotPos=InitRotPos(CardMaxCount);       }         ///        /// 初始化位置       ///        ///          ///          ///          public List InitRotPos(int count)       {                 List rotPos=new List();           float interval = (maxPos - minPos)/count;           for (int i = 0; i < count; i++)           {                         float nowPos = maxPos - interval * i;               rotPos.Add(nowPos);           }                 return rotPos;       }       // Update is called once per frame       void Update()       {                 TaskItemDetection();           RefereshCard();       }        ///        /// 添加卡牌       ///        public  void AddCard()       {                 if (cardList==null)           {                         cardList=new List();           }           if (cardList.Count>=CardMaxCount)           {                         Debug.Log("手牌数量上限");               return;           }                 GameObject item = Instantiate(cardItem,this.transform);           CardItem text=item.GetComponent();           text.RefreshData(rootPos,0,0,0);           cardList.Add(text);       }         ///        /// 手牌状态刷新       ///        public void RefereshCard()       {                 if (cardList==null)           {                        return;           }           for (int i = 0; i < cardList.Count; i++)           {             cardList[i].RefreshData(rootPos,rotPos[i],size,i);            }       }         ///        /// 销毁卡牌       ///        public  void RemoveCard()       {                 if (cardList==null)           {             return;           }           CardItem item = cardList[cardList.Count - 1];           cardList.Remove(item);           Destroy(item.gameObject);       }     	///        /// 销毁卡牌       ///        ///          public  void RemoveCard(CardItem item)       {                 if (cardList==null)           { 	        return;           }         cardList.Remove(item);           Destroy(item.gameObject);       }       private Vector3 oldmousePosition;                  ///        /// 玩家操作检测       ///        public void TaskItemDetection()       {               if (Input.GetKeyDown(KeyCode.A))           {                     AddCard();           }                }   } 

相关内容

热门资讯

来一盘!大众互娱辅助器(透明挂... 来一盘!大众互娱辅助器(透明挂)外挂透明挂辅助app(2024已更新)(哔哩哔哩)1、玩家可以在大众...
玩家必看科普!闽南旺旺麻将(好... 玩家必看科普!闽南旺旺麻将(好像真的是有挂)详细辅助挂教程1、上手简单,内置详细流程视频教学,新手小...
9分钟了解!开心泉州麻将挂是真... 9分钟了解!开心泉州麻将挂是真的吗,雀友游戏一贯有挂,曝光教程(有挂方法);1、9分钟了解!开心泉州...
七分钟详情!优乐麻将有没有挂,... 七分钟详情!优乐麻将有没有挂,越乡游双扣辅助工具(果然有辅助挂)1、该软件可以轻松地帮助玩家将越乡游...
一分钟了解!!广东雀神智能辅助... 一分钟了解!!广东雀神智能辅助器下载(透视)外挂透明挂辅助挂(2023已更新)(哔哩哔哩)1、每一步...
玩家实测!老友汇软件神器(一贯... 玩家实测!老友汇软件神器(一贯有挂)详细透视辅助教程老友汇软件神器是一种具有地方特色的麻将游戏,要想...
8分钟辅助!星悦麻将有挂吗20... 8分钟辅助!星悦麻将有挂吗2020,开心十三张辅助挂本来真的是有挂,黑科技教程(有挂攻略)星悦麻将有...
5分钟黑科技!闲来麻将,天天福... 5分钟黑科技!闲来麻将,天天福建十三张吗(果然有挂)1.天天福建十三张吗 ai辅助创建新账号,点击进...
总算了解!!微信跑得快辅助神器... 总算了解!!微信跑得快辅助神器(透明挂)外挂透明挂辅助软件(2020已更新)(哔哩哔哩);1、在微信...
揭秘!白金岛跑得快外 挂(确实... 揭秘!白金岛跑得快外 挂(确实真的有挂)详细透视教程;1、任何白金岛跑得快外 挂ai辅助神器的玩家都...