/// <summary>
/// 扇形
/// </summary>
/// <param name="player">玩家位置</param>
/// <param name="target">敌人位置</param>
/// <param name="angle">攻击角度</param>
/// <param name="radius">攻击半径</param>
/// <returns></returns>
public bool UmbrellaAttact(Transform player,Transform target,float angle,float radius)
{
//玩家指向敌人的方向向量
Vector3 attackDir = target.position - player.position;
//首先通过两个单位向量间的点乘Dot得到两个向量之间角度的余弦值
//在通过Acos得到弧度
//接下来通过弧度转角度Rad2Deg 的到两个向量之间的夹角
//真正的夹角度数
float realAngle = Mathf.Acos(Vector3.Dot(attackDir.normalized, player.forward)) * Mathf.Rad2Deg;
//判断角度是否小于技能角度的一半
//在使用向量的长度的平方来判断与半径平方的大小 使用平方运算比magnitude块很多 因为magnitude要使用勾股定理进行开方
if(realAngle<angle*0.5f&&attackDir.sqrMagnitude< radius*radius)
{
return true;
}
return false;
}
圆形攻击
/// <summary>
/// 圆形
/// </summary>
/// <param name="player">玩家位置</param>
/// <param name="target">目标位置</param>
/// <param name="radius">攻击半径</param>
/// <returns></returns>
public bool CircleAttack(Transform player,Transform target,float radius)
{
//得到玩家与被攻击物体的距离
float distance = Vector3.Distance(player.position,target.position);
if (distance < radius)
{
//在半径范围内
return true;
}
return false;
}
矩形攻击
/// <summary>
/// 矩形
/// </summary>
/// <param name="Player">玩家位置</param>
/// <param name="target">目标位置</param>
/// <param name="rectangleWide">矩形的宽度</param>
/// <param name="rectangleHigh">矩形的高度</param>
/// <returns></returns>
public bool RectangleAttack(Transform Player, Transform target,float rectangleWide,float rectangleHigh)
{
//得到玩家位置指向被攻击物体的方向向量
Vector3 dirVector = target.position - Player.position;
//与玩家位置正前方做点乘 得到投影
float forwardDistance = Vector3.Dot(dirVector, Player.forward.normalized);
if (forwardDistance>0&&forwardDistance<rectangleHigh)
{
//此时在矩形的高度范围内
//与玩家位置正右方标量继续做点乘得到投影
float rightDistance = Vector3.Dot(dirVector, Player.right.normalized);
//绝对值小于矩形的宽度的一半
if (Mathf.Abs(rightDistance)<=rectangleWide*0.5f)
{
return true;
}
return false;
}
return false;
}
通过定义float值进行倒计时如上图,进行伤害判定(通过动画的播放时长)进行倒计时,通过time.datetime进行倒计时,当时间小于1时对找到的玩家用imge.fillamount进行剪等于操作(fillmount是引用UI里图片imge里面通过)下面:
选填图片类型,填充方法,里面的fllamunt就是里面文的填充总数,在unity声明图片用图片点出来的值;