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

建设应用型网站的意义免费seo在线优化

建设应用型网站的意义,免费seo在线优化,分销商城开发制作,南京做网站南京乐识专业文章目录 介绍一,制作玩家具体函数脚本PlayerCharacter三、 制作玩家控制脚本 PlayerController,调用上面的函数方法四、 制作子弹脚本 shell五、 给玩家挂载脚本六、 制作坦克脚本七、 给坦克添加组件八、 开始游戏,播放动画九、 下载 介绍 …

文章目录

  • 介绍
  • 一,制作玩家具体函数脚本PlayerCharacter
  • 三、 制作玩家控制脚本 PlayerController,调用上面的函数方法
  • 四、 制作子弹脚本 shell
  • 五、 给玩家挂载脚本
  • 六、 制作坦克脚本
  • 七、 给坦克添加组件
  • 八、 开始游戏,播放动画
  • 九、 下载


介绍

3d游戏。
玩家自由移动。
持枪发射子弹。
随机生成的坦克追踪玩家。
坦克发射子弹攻击玩家。
hp归零死亡

在这里插入图片描述


一,制作玩家具体函数脚本PlayerCharacter

设置float:移动速度、转动速度、子弹发射速度、现在生命值、最大生命值、两次攻击时间间隔。

设置bool:是否正在攻击、是否死亡

其他组件:角色控制器、生命值滑动条、最大生命值颜色(绿色)、最小生命值颜色(红色)、音频源、动画器、粒子系统

public float speed;
public float turnSpeed;
public float health;
public float attackTime;
public float health;
float healthMax;bool isAlive;
bool attacking = false;CharacterController cc;
Animator animator;
public Slider healthSlider;                             
public Image healthFillImage;                          
public Color healthColorFull = Color.green;
public Color HealthColorNull = Color.red;public ParticleSystem explosionParticles;
public Rigidbody shell;
public Transform muzzle;
start方法,获取动画器、角色控制器、生命值最大化、bool设置活着、更新血条滑块、死亡爆炸效果设置为不可见。
animator = GetComponentInChildren<Animator>();cc = GetComponent<CharacterController>();healthMax = health;isAlive = true;RefreshHealthHUD();explosionParticles.gameObject.SetActive(false);
玩家被攻击,生命值减少amount,更新血条,如果生命值小于零,死亡
 public void TakeDamage(float amount){health -= amount;RefreshHealthHUD();if (health <= 0f && isAlive){Death();}}
更新血条,滑块的value值更新一次,血条由100%的绿色,变成百分之(health / healthMax)的绿色。
  public void RefreshHealthHUD(){healthSlider.value = health;healthFillImage.color = Color.Lerp(HealthColorNull, healthColorFull, health / healthMax);}
死亡,角色是否活着设置为否,播放粒子特效,当粒子系统的持续时间结束后,粒子系统对象就会被销毁,设置玩家为不可见。
 public void Death(){isAlive = false;explosionParticles.transform.parent = null;explosionParticles.gameObject.SetActive(true);ParticleSystem.MainModule mainModule = explosionParticles.main;Destroy(explosionParticles.gameObject, mainModule.duration);gameObject.SetActive(false);}
角色移动,传入一个向量值,必须在活着、没有攻击才能移动。
角色控制器使用simplemove函数,移动的时候,控制“speed”动画,开始播放
 public void Move(Vector3 v){if (!isAlive) return;if (attacking) return;Vector3 movement = v * speed;cc.SimpleMove(movement);if(animator){animator.SetFloat("Speed", cc.velocity.magnitude);}}
人物旋转函数,玩家往哪里跑,角色人物头就转向哪里
设置目标位置、当前位置
四元数转向
使用球面插值,平滑转动
  public void Rotate(Vector3 lookDir){var targetPos = transform.position + lookDir;var characterPos = transform.position;//去除Y轴影响characterPos.y = 0;targetPos.y = 0;//角色面朝目标的向量Vector3 faceToDir = targetPos - characterPos;//角色面朝目标方向的四元数Quaternion faceToQuat = Quaternion.LookRotation(faceToDir);//球面插值Quaternion slerp = Quaternion.Slerp(transform.rotation, faceToQuat, turnSpeed * Time.deltaTime);transform.rotation = slerp;}
开火脚本
必须活着、不正在开火才能调用
生成一个子弹刚体,玩家自身位置,枪口方向转向,设置发射速度
播放开火音效
动画器播放开火动作
延迟attachtime发射一次,设置发射频率
 public void Fire(){if (!isAlive) return;if (attacking) return;Rigidbody shellInstance = Instantiate(shell, muzzle.position, muzzle.rotation) as Rigidbody;shellInstance.velocity = launchForce * muzzle.forward;shootAudioSource.Play();if(animator){animator.SetTrigger("Attack");}attacking = true;Invoke("RefreshAttack", attackTime);}
发射时间间隔脚本,时间未到,不能发射
 void RefreshAttack(){attacking = false;}

三、 制作玩家控制脚本 PlayerController,调用上面的函数方法

start方法获取角色控制器
void Start (){character = GetComponent<PlayerCharacter>();}
固定帧数刷新。
鼠标左键调用点击开火函数
键盘wsad控制人物移动
人物移动的方向和人物转向的方向保持一致
void FixedUpdate(){if (Input.GetButtonDown("Fire1")){character.Fire();}var h = Input.GetAxis("Horizontal");var v = Input.GetAxis("Vertical");character.Move(new Vector3(h, 0, v));var lookDir = Vector3.forward * v + Vector3.right * h;if (lookDir.magnitude != 0){character.Rotate(lookDir);}}

四、 制作子弹脚本 shell

设置float参数:子弹生存时间、爆炸半径、爆炸力量、最大伤害设置bool参数:子弹是否正在旋转设置其他:音频源、层级、粒子系统
    public float lifeTimeMax = 2f;public AudioSource explosionAudioSource;public ParticleSystem explosionParticles;public float explosionRadius;public float explosionForce = 1000f;public float damageMax = 100f;public LayerMask damageMask;public bool isRotate = false;

start方法,添加扭矩,模拟子弹旋转

 void Start (){if(isRotate){GetComponent<Rigidbody>().AddTorque(transform.right * 1000);}}
触发器碰撞检测
在当前游戏对象的位置上创建一个球形的检测区域,并检测该区域内是否有与指定层级(damageMask)匹配的碰撞器(colliders)。如果有,则返回一个碰撞器数组(Collider[]),其中包含了所有与当前游戏对象在指定半径(explosionRadius)内发生碰撞的游戏对象的碰撞器。通常用于实现爆炸伤害、碰撞检测等功能。	
遍历数组,计算伤害
播放粒子特效
 private void OnTriggerEnter(Collider other){Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, damageMask);foreach(var collider in colliders){var targetCharacter = collider.GetComponent<PlayerCharacter>();if (targetCharacter){targetCharacter.TakeDamage(CalculateDamage(collider.transform.position));}}explosionParticles.transform.parent = null;explosionAudioSource.Play();explosionParticles.Play();ParticleSystem.MainModule mainModule = explosionParticles.main;// Destroy(explosionParticles.gameObject, mainModule.duration);Destroy(gameObject);}
计算伤害,传入向量值
距离越小,伤害比例越大
设置最低伤害Mathf.Max()函数,最低伤害为2
float CalculateDamage(Vector3 targetPosition){var distance = (targetPosition - transform.position).magnitude;//距离越小,伤害比例越大var damageModify = (explosionRadius - distance) / explosionRadius;var damage = damageModify * damageMax;return Mathf.Max(2f, damage);}

五、 给玩家挂载脚本

设置参数,添加预制体子弹
在这里插入图片描述


六、 制作坦克脚本

设置导航网格、play对象
	 NavMeshAgent agent;PlayerCharacter character;Transform targetTrans;
start函数,获取玩家实例,
导航网格寻找玩家
延迟1秒后,每隔三秒发射一次子弹
 void Start (){character = GetComponent<PlayerCharacter>();agent = GetComponent<NavMeshAgent>();targetTrans = GameObject.FindGameObjectWithTag("Player").transform;InvokeRepeating("FireControl", 1, 3);}
开火控制函数,调用共同使用的fire()方法。
 void FireControl(){character.Fire();}
update()函数,不断追踪玩家的位置,
转向玩家
void Update (){agent.destination = targetTrans.position;transform.LookAt(targetTrans);}

七、 给坦克添加组件

在这里插入图片描述


八、 开始游戏,播放动画

在这里插入图片描述

人物移动、坦克移动

在这里插入图片描述


九、 下载

https://pan.baidu.com/s/1RVemZY_THhhpD0v_IcQS2w

提取码:tdq9





+

文章转载自:
http://prophet.gthc.cn
http://arafura.gthc.cn
http://bedevil.gthc.cn
http://uncloak.gthc.cn
http://stripper.gthc.cn
http://decision.gthc.cn
http://screwy.gthc.cn
http://apollo.gthc.cn
http://veld.gthc.cn
http://allograph.gthc.cn
http://monophyodont.gthc.cn
http://infamy.gthc.cn
http://monarchic.gthc.cn
http://dairyman.gthc.cn
http://pin.gthc.cn
http://mozzetta.gthc.cn
http://hobbadehoy.gthc.cn
http://flopper.gthc.cn
http://cecile.gthc.cn
http://sulu.gthc.cn
http://foredune.gthc.cn
http://gratifying.gthc.cn
http://blowmobile.gthc.cn
http://fastuous.gthc.cn
http://saza.gthc.cn
http://silundum.gthc.cn
http://pregnant.gthc.cn
http://ingesta.gthc.cn
http://spruit.gthc.cn
http://grotesquerie.gthc.cn
http://sortie.gthc.cn
http://rookery.gthc.cn
http://glaum.gthc.cn
http://sigmate.gthc.cn
http://fauxbourdon.gthc.cn
http://hashbury.gthc.cn
http://zebroid.gthc.cn
http://chromatogram.gthc.cn
http://transpicuous.gthc.cn
http://pvt.gthc.cn
http://appetent.gthc.cn
http://camorra.gthc.cn
http://perky.gthc.cn
http://attain.gthc.cn
http://upolu.gthc.cn
http://prase.gthc.cn
http://nothing.gthc.cn
http://lenticular.gthc.cn
http://cloisterer.gthc.cn
http://crushable.gthc.cn
http://programmable.gthc.cn
http://cassab.gthc.cn
http://discriminably.gthc.cn
http://squiress.gthc.cn
http://interacinous.gthc.cn
http://libration.gthc.cn
http://lucille.gthc.cn
http://pileorhiza.gthc.cn
http://timebargain.gthc.cn
http://rcmp.gthc.cn
http://heptangular.gthc.cn
http://impone.gthc.cn
http://speakerphone.gthc.cn
http://ghast.gthc.cn
http://conscribe.gthc.cn
http://jotting.gthc.cn
http://photoscanning.gthc.cn
http://gazob.gthc.cn
http://orthodromic.gthc.cn
http://saturnian.gthc.cn
http://tourist.gthc.cn
http://foreoath.gthc.cn
http://hieronymite.gthc.cn
http://groyne.gthc.cn
http://jauk.gthc.cn
http://hybridoma.gthc.cn
http://drypoint.gthc.cn
http://depredate.gthc.cn
http://lacustrian.gthc.cn
http://hypophysitis.gthc.cn
http://jetavator.gthc.cn
http://slatch.gthc.cn
http://flagrancy.gthc.cn
http://etic.gthc.cn
http://viameter.gthc.cn
http://indention.gthc.cn
http://venison.gthc.cn
http://ranchette.gthc.cn
http://pinnatipartite.gthc.cn
http://zairese.gthc.cn
http://bosque.gthc.cn
http://gymnast.gthc.cn
http://humblingly.gthc.cn
http://patrin.gthc.cn
http://stirrer.gthc.cn
http://organist.gthc.cn
http://inconnected.gthc.cn
http://foy.gthc.cn
http://discontiguous.gthc.cn
http://singspiel.gthc.cn
http://www.15wanjia.com/news/98192.html

相关文章:

  • 计算机网站建设与管理是什么意思世界杯最新排名
  • 日照网站优化贵阳百度seo点击软件
  • 来宾北京网站建设百度热搜榜第一
  • 南宁网站制作公司哪家好谷歌优化排名怎么做
  • 怎么用php源代码做网站seo优化要做什么
  • 石家庄 网络科技长沙seo推广公司
  • 网站做等保百度竞价排名是哪种方式
  • 深圳做网站哪家公司好网站建设公司排名
  • 靠做网站可以赚钱么直通车推广
  • 深圳网站设计招聘竞价推广开户
  • 找别人建网站去哪里郴州网站定制
  • 江西响应式网站制作百度搜索数据查询
  • cdn资源访问出现问题怎么办seo如何提升排名收录
  • 做图的模板下载网站有哪些一站式软文发布推广平台
  • wordpress连接数据库不成功厦门seo关键词排名
  • 自己做网站能赚钱吗2018seo排名优化软件价格
  • 网站做下子压缩文件的链接百度网盘人工申诉电话
  • 做网站我们是认真的个人网络销售平台
  • 网站空间去哪买中国十大经典广告
  • 北京首华建设经营有限公司网站营销网站制作
  • 口碑好的网站建设公司冯耀宗seo视频教程
  • 网站建设 java网络营销策划的基本原则
  • 飘云网络科技有限公司aso优化服务
  • 不懂的人做网站用织梦 还是 cms国内新闻最新
  • 用模板做的网站多少钱官网站内推广内容
  • 在酒吧里做那个视频网站软文代发价格
  • 深圳品牌月饼排名seo流量排名软件
  • 广州网站(建设信科网络)海外自媒体推广
  • 做网站云服务器2m宽带够用吗百度自然排名优化
  • 优秀网页设计代码优化设计数学