完整被动技能代码

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. 站在Java的角度看LinkedList

    站在Java的角度看,玩队列不就是玩对象引用对象嘛! public class LinkedList<E> implements List<E>, Deque<E> ...

  2. vim 打开乱码

    首先,你需要搞清楚vimrc所在的位置.一般来说,在linux系统里,应该是这样 Linux: /usr/share/vim/vimrc在Windows系统,应该是在vim的安装目录 Windows: ...

  3. Openjudge-计算概论(A)-单词翻转

    描述: 输入一个句子(一行),将句子中的每一个单词翻转后输出. 输入只有一行,为一个字符串,不超过500个字符.单词之间以空格隔开.输出翻转每一个单词后的字符串,单词之间的空格需与原文一致. 样例输入 ...

  4. C# 二维数组和集合

    本次课我主要学习了二维数组和集合的部分内容. 在二维数组的部分中,我主要学习了二维数组的定义方法:int [,] array=new int [4,2];做了一个小练习:用二维数组打印自己的姓氏. s ...

  5. 17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行。请采用循环控制语句来实现。 (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和。) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1

    17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行.请采用循环控制语句来实现. (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和.) 1 1 1 1 ...

  6. Windows下为Python编译C扩展模块

    工具:CodeBlocks 13.12 步骤 1 打开CodeBlocks新建工程:Shared library   --   c    --  sample    [默认GUN GCC Compli ...

  7. HDU 1969 Pie

    二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...

  8. Tarjan算法求解无向连通图的割点、割边、点双连通分量和边双连通分量的模板

    历时好几天,终于完工了! 支持无向图四种功能:1.割点的求解 2.割边的求解 3.点双连通分量的求解 4.边双连通分量的求解 全部支持重边!!!!全部支持重边!!!!全部支持重边!!!! 测试数据: ...

  9. ios ViewController的生命周期分析和基本使用逻辑

    按结构可以对iOS的所有ViewController分成两类:1.主要用于展示内容的ViewController,这种ViewController主要用于为用户展示内容,并与用户交互,如UITable ...

  10. android抓日志

    1. adb logcat -c 清楚以前的日志 adb logcat -s 过滤 adb logcat -s *:E adb logcat -v 指定输出的格式 adb logcat -v brie ...