完整被动技能代码

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. webapi中的Route的标签的命名参数name的使用

    Route Names In Web API, every route has a name. Route names are useful for generating links, so that ...

  2. php基础的第一天 任务点滴,event对象方法概括 ing....

    day1 任务 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  3. Linux下gcc编译生成动态链接库*.so文件并调用它【转载】

    动态库*.so在linux下用c和c++编程时经常会碰到,最近在网站找了几篇文章介绍动态库的编译和链接,总算搞懂了这个之前一直不太了解得东东,这里做个笔记,也为其它正为动态库链接库而苦恼的兄弟们提供一 ...

  4. LibRTMP优化之调整输出块大小

    1. 为什么要调整输出块大小 首先在RTMP_Connect0函数中LibRTMP是关闭了Nagle算法这个TCP选项的,为了实时性这样做是好的,但是要注意到LibRTMP的结构体RTMP的成员是有m ...

  5. 恢复SQLSERVER被误删除的数据(转)

    恢复SQLSERVER被误删除的数据 曾经想实现Log Explorer for SQL Server的功能,利用ldf里面的日志来还原误删除的数据 这里有一篇文章做到了,不过似乎不是所有的数据类型都 ...

  6. boost.spirit之解析C++头文件

    环境:win7_64旗舰版,VS2008 场景:C++与lua交互是比较繁琐的,当我们编写一个C++类后,如果要给lua使用,就必须写一个lua包装类,将lua与原始C++类关联起来.其实这部分代码编 ...

  7. Apache Commons DbUtils 快速上手

    原文出处:http://lavasoft.blog.51cto.com/62575/222771 Hibernate太复杂,iBatis不好用,JDBC代码太垃圾,DBUtils在简单与优美之间取得了 ...

  8. ZOJ 1967 POJ 2570 Fiber Network

    枚举起点和公司,每次用DFS跑一遍图,预处理出所有的答案.询问的时候很快就能得到答案. #include<cstdio> #include<cmath> #include< ...

  9. OpenVPN客户端解析

    windows版本的VPN客户端,实际上就是一个外壳,创建了图形界面,托盘,和 右键菜单, 在connect的动作里,实际上是通过cmd调用 openvpn.exe openvpn --config ...

  10. 好玩的获取目录信息的例子[C#]

    DirectoryInfo dirinfo = new DirectoryInfo("d:\\111"); DirectoryInfo[] dirs = dirinfo.GetDi ...