- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
來自:UnityTerminator- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SkillRange {
- /// <summary>
- /// 扇形范围判定
- /// </summary>
- /// <returns><c>true</c>, if range was curved, <c>false</c> otherwise.</returns>
- /// <param name="self">Player.</param>
- /// <param name="enemy">Enemy.</param>
- /// <param name="maxDiatance">Max diatance.</param>
- /// <param name="maxAngle">Max angle.</param>
- public static bool CurveRange(Transform self,Transform enemy,float maxDiatance,float maxAngle){
- Vector3 playerDir = self.forward;
- Vector3 enemydir = (enemy.position - self.position).normalized;
- float angle = Vector3.Angle (playerDir, enemydir);
- float distance = Vector3.Distance (enemy.position, self.position);
- if (angle <= maxAngle / 2 && distance <= maxDiatance) {
- return true;
- } else {
- return false;
- }
- }
- /// <summary>
- /// 圆形范围判定
- /// </summary>
- /// <returns><c>true</c>, if range was curved, <c>false</c> otherwise.</returns>
- /// <param name="self">Player.</param>
- /// <param name="enemy">Enemy.</param>
- /// <param name="maxDiatance">Max diatance.</param>
- public static bool CurveRange(Transform self,Transform enemy,float maxDiatance){
- float distance = Vector3.Distance (enemy.position, self.position);
- if (distance <= maxDiatance) {
- return true;
- } else {
- return false;
- }
- }
- /// <summary>
- /// 矩形范围判定
- /// </summary>
- /// <param name="self"></param>
- /// <param name="enemy"></param>
- /// <param name="maxWidth"></param>
- /// <param name="maxHeight"></param>
- /// <returns></returns>
- public static bool SquareRange(Transform self, Transform enemy, float maxWidth, float maxHeight)
- {
- Vector3 enemyDir = enemy.position - self.position;
- float distance=Vector3.Distance(enemy.position,self.position);
-
- float angle = Vector3.Angle(enemyDir, self.forward);
- if ( angle<= 90)
- {
- float z = distance * Mathf.Cos(angle * Mathf.Deg2Rad);
- float x = distance * Mathf.Sin(angle * Mathf.Deg2Rad);
- if (x<=maxWidth / 2 && z<=maxHeight)
- {
- return true;
- }
- }
- return false;
- }
- }
复制代码 |
|