Unity实战篇:利用Easy Touch实现Moba游戏技能释放 (指向性追踪技能,范围AOE技能)

编程入门 行业动态 更新时间:2024-10-04 11:16:01

Unity实战篇:利用Easy Touch实现Moba游戏<a href=https://www.elefans.com/category/jswz/34/1769551.html style=技能释放 (指向性追踪技能,范围AOE技能)"/>

Unity实战篇:利用Easy Touch实现Moba游戏技能释放 (指向性追踪技能,范围AOE技能)

<2>指向性追踪技能,通过射线检测决定施法目标,这仅仅是一个思路,对于普通攻击,只需要检测人物周身敌人的血量来选择目标即可。

<3>范围AOE技能同理,只是把Slider换成普通的圆形image,根据摇杆与摇杆背景距离之比和偏移角度按比例转换到技能辅助显示上(这个比例按自己需求来设置),并且在指定位置释放范围AOE技能。

效果图

直接ctrl+d一份slider

由于我们这个技能释放范围是一定的所以直接把值设置为最大值。

skill2摇杆

脚本

        public GameObject go;//用来暂时储存相对偏移角度,方便计算public GameObject skill2;public GameObject SKILL2;//摇杆public Slider Skill2Slider;public Image skill2Image;//当我们选择到目标时,将它的指示器改为红色

OnEnable()初始化,同上一篇

private void OnEnable(){// When the tank is turned on, reset the launch force and the UI#初始化坦克数据和UIm_CurrentLaunchForce = m_MinLaunchForce;Skill1Slider.value = m_MinLaunchForce;m_ChargeSpeed = (m_MaxLaunchForce - m_MinLaunchForce) / m_MaxChargeTime;skill1.SetActive(false);skill2.SetActive(false);}

修改Fire函数

private void Fire(bool follow, GameObject target = null){timeVal = 0.0f;//重置时间标志// Create an instance of the shell and store a reference to it's rigidbody.//实例化炮弹Rigidbody shellInstance =Instantiate (m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;if(follow){shellInstance.gameObject.GetComponent<ShellExplosion>().targetEnemy = target;//设置追踪对象shellInstance.useGravity = false;//如果是有目标的,我们要把炮弹重力设为零}else// Set the shell's velocity to the launch force in the fire position's forward direction.//设置炮弹速度shellInstance.velocity = m_CurrentLaunchForce * m_FireTransform.forward;// Change the clip to the firing clip and play it.//播放发射炮弹声音m_ShootingAudio.clip = m_FireClip;m_ShootingAudio.Play ();// Reset the launch force.  This is a precaution in case of missing button events.//重置发射力 m_CurrentLaunchForce = m_MinLaunchForce;}

事件函数

public void OnSkill2Down(){skill2.gameObject.SetActive(true);}public void OnSkill2Pressed(){offset = Vector3.Angle(SKILL2.transform.localPosition, new Vector3(0, 1, 0));if (SKILL2.transform.localPosition.x < 0){offset = -offset;}go.transform.rotation = Quaternion.AngleAxis(offset, new Vector3(0, 1, 0));//绕Y轴旋转offset度,达到同步效果FindTarget();}public void OnSkill2Up(){skill2Image.color = Color.white;skill2.gameObject.SetActive(false);if(FindTarget()){GameObject go = FindTarget();transform.rotation = Quaternion.AngleAxis(offset, new Vector3(0, 1, 0));//绕Y轴旋转offset度,达到同步效果Fire(true,go);}}

FindTarget函数

private GameObject FindTarget(){Ray ray = new Ray(transform.position, go.transform.forward);RaycastHit hit;if (Physics.Raycast(ray, out hit, 100)){if (hit.transform.tag == "Player")//这里是敌人的tag{skill2Image.color = Color.red;return hit.transform.gameObject;}else{skill2Image.color = Color.white;return null;}}else{skill2Image.color = Color.white;return null;}}

ShellExplosion类

只需要加上这一句即可,用来追踪。

注册事件

更多推荐

Unity实战篇:利用Easy Touch实现Moba游戏技能释放 (指向性追踪技能,范围AOE技能)

本文发布于:2024-02-13 22:44:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1761119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:技能   指向性   实战篇   游戏   Easy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!