当前位置: 首页 > news >正文

做音箱木工网站百度搜索引擎下载免费

做音箱木工网站,百度搜索引擎下载免费,东莞开发公司网站建设,定制设计软件AI:原地巡逻自动攻击型 AI会在横版地图上向左向右移动,移动一段距离后会原地停止移动,等待一段时间后,会随机向左或向右移动,以此循环,其中AI移动速度,移动时间、停留时间均可以自行调控&#…

AI:原地巡逻自动攻击型

AI会在横版地图上向左向右移动,移动一段距离后会原地停止移动,等待一段时间后,会随机向左或向右移动,以此循环,其中AI移动速度,移动时间、停留时间均可以自行调控,当人物进入怪物攻击范围后 会自动面向人物进行攻击,攻击时不会移动,直至人物离开攻击范围,怪物受到攻击后会闪红,有血量:
在这里插入图片描述
脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ChameleonController : MonoBehaviour
{public static ChameleonController chameleonController;private void Awake(){chameleonController = this;}Animator animator;Rigidbody2D rg;public float MoveSpeed = 0;float changeTime = 0;float time = 0;//随机时间public float minTime = 0;public float maxTime = 0;int direction = 1;float distance_ = 0;bool isChange = false;bool canHit = false;Transform PlayerTransform;public float Distance = 0;float Dwell_gap = 0; //停留时间float Dwell_Cumulative = 0; //停留时间累积public float DwellMinTime = 0;public float DwellMaxTime = 0;float moveTime = 0; //行走时间//行走的最大时间和最短时间设定public float moveMinTime = 0;public float moveMaxTime = 0;float moveTimeCumulative = 0;bool isDwell = false;bool isDwellRange = false;bool CanMove = false;bool CanCount = false;bool CanTimeCumulative = false;bool isAttacking = false;bool isAttacked = false;public bool TrackPlayer = false;public float TrackSpeed = 0;public float CurrentPlayer = 0;public float Life_value = 0;public float hitTime = 0;bool isHit = false;float time1 = 0;GameObject gm;bool isinvincible = false;void Start(){animator = GetComponent<Animator>();rg = GetComponent<Rigidbody2D>();CanMove = false;CanCount = true;}void Update(){PlayerTransform = GameObject.Find("Player").transform;//得到与玩家的距离distance_ = Mathf.Sqrt(Mathf.Abs(PlayerTransform.transform.position.x - transform.position.x) * Mathf.Abs(PlayerTransform.transform.position.x - transform.position.x) +Mathf.Abs(PlayerTransform.transform.position.y - transform.position.y) * Mathf.Abs(PlayerTransform.transform.position.y - transform.position.y));time = time + Time.deltaTime;if(isChange==false){changeTime = Random.Range(minTime, maxTime);isChange = true;}transform.localScale = new Vector3(-direction, 1, 1);if (time > changeTime){direction = -direction;transform.localScale = new Vector3(-direction, 1, 1);time = 0;isChange = false;}//判断是否在攻击距离之内if(distance_<Distance){canHit = true;}else{canHit = false;}if(canHit){//判断玩家在怪物的哪边if (PlayerTransform.transform.position.x < transform.position.x){direction = 1;animator.SetBool("attack", true);GMF_PlayerController._PlayeController.inJured(CurrentPlayer);transform.localScale = new Vector3(direction, 1, 1);}else{direction = -1;animator.SetBool("attack", true);transform.localScale = new Vector3(direction, 1, 1);GMF_PlayerController._PlayeController.inJured(CurrentPlayer);}}else{animator.SetBool("attack", false);}//随机暂停时间 开始暂停 播放停留动画 人物停止移动 生成暂停时间if(CanCount){isDwellRange = true;CanTimeCumulative = true;CanCount = false;}if(isDwellRange) //设置停留动画 设置暂停时间 {Dwell_gap = Random.Range(DwellMinTime, DwellMaxTime);animator.SetBool("idem", true);animator.SetBool("run", false);CanMove = false;isDwellRange = false;}if (CanTimeCumulative){Dwell_Cumulative = Dwell_Cumulative + Time.deltaTime;}if (Dwell_Cumulative > Dwell_gap) //超过暂停时间 停留结束 结束停留动画 生成行走时间 开始行走动画{animator.SetBool("idem", false);animator.SetBool("run", true);moveTime = Random.Range(moveMinTime, moveMaxTime);CanMove = true;Dwell_Cumulative = 0;CanTimeCumulative = false;}//行走时间结束 if(CanMove){moveTimeCumulative = moveTimeCumulative + Time.deltaTime;if(moveTimeCumulative>moveTime){CanMove = false;moveTimeCumulative = 0;CanCount = true;}}if(Life_value<=0){Destroy(this.gameObject);}if (isHit){// animator.SetBool("current", true);time1 = time1 + Time.deltaTime;if (time1 > hitTime){animator.SetBool("current", false);isinvincible = false;isHit = false;time1 = 0;}}}private void FixedUpdate(){//没有停留就可以移动if(CanMove){MoveMent();}}void MoveMent(){if(TrackPlayer==false){rg.velocity = new Vector2(1 * direction * MoveSpeed, 0);}else{if (distance_ < Distance){if(PlayerTransform.transform.position.x < transform.position.x){rg.velocity = new Vector2(-1 * TrackSpeed, 0);}else{rg.velocity = new Vector2( 1 * TrackSpeed, 0);}}}}private void OnTriggerExit2D(Collider2D collision){if(collision.tag=="Player"){CanMove = true;}}private void OnTriggerEnter2D(Collider2D collision){if (collision.tag == "Player"){CanMove = false;}if (collision.tag == "bullte"){if(isinvincible==false){animator.SetBool("current", true);isinvincible = true;isHit = true;}}}public void Current(float value){Life_value = Life_value - value;}}

AI属性面板:
在这里插入图片描述

AI动画设置,注意动画的命名要一样,不然需要修改代码:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
需要注意的是,每个动画没有过度,直接切换,不然会有一些卡顿
在这里插入图片描述
人物标签需要设置为Player
在这里插入图片描述
怪物标签需要设置为Chameleon
在这里插入图片描述
如果想让怪物之间不能够相互碰撞,让怪物和玩家间可以相互碰撞,可以给怪物AI和玩家分别设置一个碰撞层级,方法如下:
首先我们需要为人物和怪物设置分别设置一个层级,一个是人物层级,一个是怪物层级,点击Layer下拉菜单:
在这里插入图片描述
添加一个层级:
在这里插入图片描述
接下来:
在这里插入图片描述
在编辑下拉菜单下找到Project Setting,将不想发生碰撞的两个层级较差的对勾取消掉
在这里插入图片描述
子弹攻击,AI掉血摧毁设置:
在这里插入图片描述
bullte为子弹,需要有boxCollider2D,勾选Is Trigger在这里插入图片描述

http://www.lbrq.cn/news/2387359.html

相关文章:

  • 做网站的需要什么软件专业提升关键词排名工具
  • 做网站不赚钱中国品牌策划公司排名
  • 手机网站切图学编程的正规学校
  • 网站建设开发背景91关键词排名
  • 松江区建设交通委员会网站电脑培训网
  • 网站建设制作免费咨询推广平台 赚佣金
  • 十大免费ppt课件网站石家庄网站建设
  • 做视频网站视频存放问题seo网站内容优化
  • 大连网站建设设计公司哪家好宁国网络推广
  • 电商网站建设教案软文怎么写吸引人
  • 要做网站到哪里做免费b站推广入口2023
  • 做网站需要什么资质查关键词热度的网站
  • 产品介绍网站设计武汉百捷集团百度推广服务有限公司
  • 辽阳太子河网站建设西安网站建设公司排行榜
  • 用ci框架如何做动态网站网站代运营推广
  • 山东省中国建设银行网站家电企业网站推广方案
  • 免费的软件网站建设怎么建网站卖东西
  • 做阅读任务挣钱的网站百度排名查询
  • 做茶叶网站公司杭州seo按天计费
  • 丰镇网站建设广东网络seo推广公司
  • 免费高清logo在线成都seo技术经理
  • 天津网站建设电焊机推广平台哪儿有怎么做
  • 企业网站建设需要什么搜索引擎优化排名seo
  • 免费建网站软件下载南昌搜索引擎优化
  • 在百度上做网站怎么做百度排名规则
  • 烟台市建设工程质量检测网站怎么开网站
  • 专业网站建设哪个好短网址生成网站
  • 建设网站的工具佛山优化推广
  • 马蜂窝旅游网站怎么做百度资源搜索平台
  • 北京网站建设模板下载百度人工客服在哪里找
  • ABP VNext + Kubernetes Istio:微服务网格实战指南
  • 设计模式五:桥模式(Bridge Pattern)
  • MySQL:数据类型
  • RAG深入了解P1:从RAG类型出发看优化点
  • Redis7 底层数据结构解析
  • Java学习--JVM(2)