完整被动技能代码

using UnityEngine;
using System.Collections; public class AI : MonoBehaviour
{ private Hashtable table;
void Start()
{
table = new Hashtable();
} void Update()
{ }
//离开碰撞
void OnTriggerExit(Collider other)
{
//如果消失
if (other.transform.name == otherName)
{
touch = false;
otherName = "";
}
table.Remove(other.transform.name);
StartCoroutine(Independent(0.1f));
}
//多物体碰撞 ,当移除后,必须检测已有碰撞中是否还有符合条件的
IEnumerator Independent(float i)
{
if (touch == false) //没碰
{
foreach (DictionaryEntry de in table)
{
//检测碰撞,发现导入方法
//加入
Transform transform = de.Value as Transform;
if (OnDetection(transform))
{
otherName = transform.name;
touch = true;
}
}
}
yield return new WaitForSeconds(i);//n秒执行一次 遍历,提高效率
} private bool touch = false;//和目标物体发生碰撞没有
private string otherName;//目标物体
//进入碰撞
void OnTriggerEnter(Collider other)
{
table.Add(other.transform.name, other.transform); if (this.transform.GetComponent<Attribute>().att == )
{
//测试用
print(other.transform.name);
print(table.Count);
}
if (touch == false) //没碰
{
foreach (DictionaryEntry de in table)
{
//检测碰撞,发现导入方法
//加入
Transform transform = de.Value as Transform;
if (OnDetection(transform))
{
otherName = other.transform.name;
touch = true;
}
}
}
}
//检测碰撞
bool OnDetection(Transform tr)
{
if (tr.name != transform.name)//碰点不是自己
{
//这里写方法判断逻辑
if (tr.GetComponent<Attribute>().att != this.transform.GetComponent<Attribute>().att)//不同属性对打,相同属性 不打
{
return true;
}
else
{//重新选择敌人
return false;
}
}
return false;
} //逗留碰撞
void OnTriggerStay(Collider other)
{
if (other.transform.name == otherName)
{
//检测距离
float distance = Vector3.Distance(this.transform.position, other.transform.position);//距离公式 //根据距离 发射子弹,
if (this.transform.name == "momo(Clone)001")//测试用
{
// this.transform.LookAt(other.transform);
print(this.transform.name + "发射" + otherName);
}
}
} }
using UnityEngine;
using System.Collections; public class Attribute : MonoBehaviour { public string name;
public int blood;//血
public int speed;//移动速度
public int aggressivity;//攻击力
public int att;//属性
void Start () { } void Update () { }
}

AI 人工智能 探索 (二)的更多相关文章

  1. AI 人工智能 探索 (四)

    在写之前,先对昨天寻路插件再做一些补充,因为该插件不是很完善,所以当我发现有不能满足需求的时候,就会试图更改源代码,或增加接口来符合我的需求. 昨天补充了一条是 自身转向代码,今天补充另外一条,是及时 ...

  2. AI 人工智能 探索 (三)

    三类子弹的设计 using UnityEngine; using System.Collections; public class AI : AssembleModel { private Hasht ...

  3. AI 人工智能 探索 (七)

    我简单画了一幅图,来讲下 ai 中的设计模式.图形中的这些人物,我想大家都能看的明白. 当 盗贼出现,人们发现了他们,就 呼叫 主类,然后主类再  通知 下面对应的管理局,然后管理局再 分配人手过去 ...

  4. AI 人工智能 探索 (六)

    这次我为 角色 attribute 添加了 多个属性 其中 att 是 好人 坏人 等属性, 显然 数字不同 就要打起来. grade 是智商属性 ,今天先做了 3的智商.也就是小兵智商.碰到就打 逃 ...

  5. AI 人工智能 探索 (五)

    我们把做好的 角色 拖到 内存池,如图所示,这样我们可以动态生成角色并给予他 寻路目标. //逗留碰撞 void OnTriggerStay(Collider other) { if (other.t ...

  6. AI 人工智能 探索 (十)

    呼叫事件图形结构如下 蓝色代表 警察局 红色代表警察 黄色代表 死亡人 蓝色球代表呼救人 黑色代表 敌人 警察目标是 攻击 黑色人,但 路中 会碰到 黄色人,如果警察有 救人功能 则会先救人去医院再看 ...

  7. AI 人工智能 探索 (九)

    链接:http://pan.baidu.com/s/1c0AM3g0 密码:uccw 今天补充 创建物体 移动物体 ,当点击创建后 ,会出来一个 上图的 ui,他跟随 物体,当你把物体拖动到 指定的地 ...

  8. AI 人工智能 探索 (八)

    绑定下,用来释放内存 布局框架.链接:http://pan.baidu.com/s/1eQzSXZO 密码:25ir 这次 我采用 ngui 来设定界面.除工具栏模块外,其他各类ui模块都是 内存池动 ...

  9. AI 人工智能 探索 (一)

    碰撞检测 //逗留碰撞 void OnTriggerStay (Collider other) { if (other.transform.name == name) { //检测距离 //根据距离 ...

随机推荐

  1. Dubbo协议与连接控制

    协议参考手册 (+) (#) 推荐使用Dubbo协议 性能测试报告各协议的性能情况,请参见:性能测试报告 (+) dubbo:// (+) (#) Dubbo缺省协议采用单一长连接和NIO异步通讯,适 ...

  2. digitalocean解释:private networking和user data、IPv6是什么意思

    digitalocean vps后台新建droplet的时候,底部会有available settings,里面有四个选项,大多数用户不懂啥意思,我今天解释下: Private Networking ...

  3. 第二次冲刺spring会议(第二次会议)

    [例会时间]2014/5/5 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇 界面的一些修改如下

  4. Openjudge-计算概论(A)-求一元二次方程的根

    描述: 利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b - sqrt(b*b-4*a*c))/(2*a)求一元二次方程ax2 + bx + c =0的根 ...

  5. 【Vmware】VirtualBox下虚拟机的网络配置

    1.VirtualBox的提供了四种网络接入模式,它们分别是:1.NAT    网络地址转换模式(NAT,Network Address Translation)2.Bridged Adapter   ...

  6. ios navigationController代码创建

    1.新建类文件FirstViewController,subClass of:UIViewController 2.新建类文件MYNavigationController,subClass of:UI ...

  7. setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientific Linux

    This is a guide on setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientif ...

  8. kvstore之memcached为存储介质

    ecstore中kvstore选用memcached作为存储介质 kvstore存储类选用base_kvstore_memcached(app/base/lib/kvstore/memcached.p ...

  9. 终端中出现While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod错误的修改方法

    把输入终端的sudo gem install cocoapods改为 sudo gem install -n /usr/local/bin/ cocoapods即可

  10. nodejs【伪】入门教程

    声明: 本文适合白的不能再白的小白 不要被标题误导,本文不会讲nodejs基础,只是本人学习流程和资料的一个整合 如果想找一大堆教程自己看,没有电梯,自己拉到文章最下方吧   一.nodejs是什么 ...