unity3D__主角打怪物
来源:互联网 发布:苹果铃声截取软件 编辑:程序博客网 时间:2024/05/17 07:58
欢迎大家关注我的日志,今天简单的讲讲主角打怪物:
//主角走动
private NavMeshAgent agent;
public GameObject hero;
public static float lifeTime = 0f;
public bool flag=false ;
//private float timer=1f;
void Start () {
agent =GetComponent <NavMeshAgent >();
}
// Update is called once per frame
void Update () {
if(Input .GetMouseButtonDown (0)){
Ray ray=Camera .main .ScreenPointToRay (Input .mousePosition );
RaycastHit hitInfo;
if (Physics .Raycast (ray ,out hitInfo )){
agent .SetDestination (hitInfo .point);
}
}
//调用主角的方法,实现主角的各种动作
if (flag) {
work ();
//timer -= Time .deltaTime;
//if (timer <= 0)
// {
//print ("AAAAAAAAA");
flag = false;
//timer = 1f;
//}
}
else
{
if (agent .remainingDistance == 0)
{
idle ();
}
else
{
walk ();
}
}
}
void idle(){
hero .transform .animation .Play ("idle");
}
void walk(){
hero .transform .animation .Play ("walk");
}
void work(){
hero .transform .animation .Play ("idle to working");
}
//实现碰撞效果,使主角攻击怪物
void OnTriggerEnter(Collider other){
if (other.CompareTag("a"))
{
flag = true;
}
}
}
//给主角武器加碰撞
int life=2;//怪物生命值为2
void Start () {
}
void OnTriggerEnter(Collider other) {
if (other.CompareTag("b"))
{
life --;
if (life ==0){
Destroy(this .gameObject);
}
}
}
如果大家还有什么困难的话可以关注我的日志:
http://unity.gopedu.com/home.php?mod=space&do=blog&view=me
还可以关注我们的狗刨网:
http://unity.gopedu.com
- unity3D__主角打怪物
- unity--怪物打主角
- unity3D__球打砖块
- unity小项目主角打击怪物
- 打怪物框架示意图(cocos creator)
- unity3D__周结
- unity3D__总结
- unity3D__总结
- android 游戏 实战 打飞机 实现主角以及主角相关元素(3)
- Unity3D__封装、继承
- quick-cocos2d-x 飞机大战(打飞机)小demo教程------主角飞机类
- android 游戏 实战打飞机游戏 怪物(敌机)类的实现(4)
- unity3D__常用核心对象例题
- unity3D__忽略碰撞和射线
- 指南:主角
- 杀死主角
- 游戏主角
- 技术主角
- c语言实现:将字符串颠倒,12345678变成 87654321
- 用R语言解析字符串
- hadoop运行命令总结(更新中)
- 资源向导之 "Operating System"
- 使用distcp在hadoop集群之间拷贝文件w
- unity3D__主角打怪物
- GDAL不支持创建PCIDSK的面状矢量格式
- 常用Linux命令(下)
- Linux 内核等待队列解析
- 消息转发
- windows录音程序原理
- 在grep中使用tab符号
- 怎么代理手机吸费 供应电话吸费 电话群呼器
- MFC写的一个界面遇到的问题