什么是网站推广策略,云南固恒建设集团有限公司网站,网站的优化和推广方案怎么写,建设银行网站怎么开通手机短信每日一句#xff1a;保持热爱#xff0c;奔赴下一场山海#xff0c;愿大学生活#xff0c;光芒万丈、快乐昂扬 目录
物理引擎
刚体Rigidbodyˈrɪdʒɪd/
碰撞器collider/kəˈlaɪdə(r)/
碰撞条件
碰撞三阶段
触发器
触发条件
触发三阶段
如果物体移动速度过快保持热爱奔赴下一场山海愿大学生活光芒万丈、快乐昂扬 目录
物理引擎
刚体Rigidbodyˈrɪdʒɪd/
碰撞器collider/kəˈlaɪdə(r)/
碰撞条件
碰撞三阶段
触发器
触发条件
触发三阶段
如果物体移动速度过快碰撞检测失效—解决方案
开始时使用射线检测
武器模块
枪
策划
需求分析
子弹
敌人子弹 物理引擎
模拟真实世界中物体特性的引擎
刚体Rigidbodyˈrɪdʒɪd/
·带有刚体组件的游戏物体
刚体组件可使游戏对象受物理引擎控制在受到外力时产生真实世界中的运动重力、弹力、摩擦力
碰撞器collider/kəˈlaɪdə(r)/ 物理材质 ·用于调整碰撞对象的摩擦力和反弹效果 project—(右键)Physic Material/məˈtɪəriəl/ 属性 动态摩擦力Dynamic Friction/daɪˈnæmɪk ˈfrɪkʃn/ 静态摩擦力Static Friction 弹力Bounciness 摩擦力合并模式Friction Conbine Mode 合并反弹 Bounce/baʊns/ Combine/kəmˈbaɪn/ 平均值Average/ˈævərɪdʒ/ 最小Min 最大Max 相乘Multipy 碰撞条件 ·两者都具有碰撞器组件 ·运动的物体具有刚体组件 碰撞三阶段 进入碰撞时执行接触的第一帧执行 void OnCollisionEnter(Collision/kəˈlɪʒ(ə)n/ collother) 碰撞体与刚体接触时每帧执行 void OnCollisionStay(Collision collother) 停止碰撞时执行 void OnCollisionExit(Collision collother) private void OnCollisionEnter(Collision collother)
{ // collother:获取对方碰撞器组件
collother.collider.GetComponent //获取第一个接触点
ContactPoint/ˈkɒntækt/ cpcollother.contacts[0];
//cp.point接触点的世界坐标
//cp.normal接触面法线
}
触发器
·碰撞器组件collider且Is Trigger属性被勾选的物体
现象无碰撞效果
触发条件 ·两者都具有碰撞组件 ·其中一个带有刚体组件 ·其中一个勾选Is Trigger 触发三阶段 当碰撞体进入触发器时执行 void OnTriggerEnter(Collider cldother) 当碰撞体与触发器接触时执行 void OnTriggerStay(Collider cldother) 当停止触发时执行 void OnTriggerExit(Collider cldother) private void OnTriggerEnter(Collider collother)
{ // collother:就是对方碰撞器组件
collother.GetComponent
}
如果物体移动速度过快碰撞检测失效—解决方案
开始时使用射线检测 private void Start() { RaycastHit hit; //重载15Raycast(起点坐标方向受击物体信息距离检测的层) if(physics.Raycast(this.transform.position,this.transform.forward,out hit,100,mask)) {//检测到物体 targetPoshit.point;//击中的位置 } else {//没有检测到物体 targetPosthis.transform.positionthis.transform.forward*100;//物体正前方100米 } } void Update() { this.transform.position Vector3.MoveTowards(this.transform.position,targetPos,Time.deltaTime*100); if((this.transform.position-targetPos).sqrMagnitude/ˈmæɡnɪtjuːd/0.1f) {print(“接触目标点”); Destory(this.gameObject);//销毁子弹 } 武器模块
枪
策划
·如果弹匣内装有子弹可以发射否则等待更换弹匣
·发射子弹时播放音效、动画、显示火花
·玩家的枪可以单发或连发
需求分析
·创建脚本—枪Gun提供开火更换弹匣功能
·创建脚本—单发枪SingleGun继承自Gun根据玩家输入调用相应开关、更换弹匣方法
·创建脚本—连发枪AutomaticGun,继承自Gun
子弹
策划
主角子弹
·根据击中敌人的部位减血
·子弹飞行到目标点销毁并创建相应特效
敌人子弹
·击中玩家后减血
·子弹飞行到目标点销毁并创建相应特效
·朝向玩家头部发射飞行速度较慢便于玩家躲避
需求分析
·创建脚本—子弹Bullet计算攻击的目标点执行移动创建接触特效
·创建脚本—玩家子弹PlayerBullet,继承自Bullet根据击中敌人部位减血
·创建脚本—敌人子弹EnemyBullet,继承自Bullet根据击中玩家后减血 EnemyAI类(续) private Gun gun; private void Start() {gunGetComponentInChildrenGun();} Attack() public float delay; motor.LookRotation(playerStatusInfo.Instance.headTF.position); if(atkTimerTime.time) {Invoke(“Shoot”,delay);} private void Shoot() {{//发射子弹建议使用动画事件替代 //发起攻击从枪口位置指向玩家头部位置 gun.Firing(playerStatusInfo.Instance.headTF.position-gun.firePointTF,position); EnemyMotor类续 public void LookRotation(Vector3 targetPoint) {//当前物体注视目标点旋转 this.transform.LookAt(targetPoint);//会出现头部高于自身物体 人物倾斜旋转速度过快解决— targetPoint.ythis.transform.position.y; 或 Quaternion dir Quaternion.LookRotation(targetPoint - this.transform.position); Quaternion rotate Quaternion.Lerp(this.transform.rotation, dir, 20 * Time.deltaTime); Vector3 euler rotate.eulerAngles; //仅仅沿Y轴旋转 this.transform.eulerAngles new Vector3(0, euler.y, 0); 上波代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{ [HideInInspector]public float atk;/// summary/// 攻击距离/// /summarypublic float attackDistance 20;/// summary/// 射线检测层/// /summarypublic LayerMask mask;protected RaycastHit hit;//受击目标信息private Vector3 targetPos;/// summary/// 移动速度/// /summarypublic float moveSpeed200;//计算目标点private void CalculateTargetPoint(){//当前位置枪口位置当前方向枪口方向受击目标信息攻击最大距离射线检测层if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, attackDistance, mask))targetPos hit.point;elsetargetPos this.transform.position this.transform.forward * attackDistance;}//移动private void Movement(){this.transform.position Vector3.MoveTowards(this.transform.position, targetPos, moveSpeed * Time.deltaTime);}//到达目标点销毁创建相关特效//根据目标点物体的标签hit.collider.tag创建特效private void Awake(){CalculateTargetPoint();}// Update is called once per framevoid Update(){Movement();//如果到达目标点if((this.transform.position-targetPos).sqrMagnitude0.1f){Destroy(this.gameObject);GenerateContactEffect()}}/// summary/// 生成特效/// /summaryprivate void GenerateContactEffect(){if (hit.collider null) return;//根据目标物体标签创建相应特效//switch(hit.collider.tag)【弊端】每次增加标签都得创建代码//{// case :// break;//}//特效名称存放路径接触物体标签//资源较多通过代码读取资源用Recources读取资源必须放到Recources目录下//根据标签加载资源消耗性能【建议使用对象池替代】GameObject prefabGo Recources.LoadGameObject(目录/hit.collider.tag);if(prefabGo)//创建资源(资源预设体目标点位置向法线方向移动0.01米z轴朝向法线方向Instantiate(prefabGo,targetPoshit.normal*0.01f,Quaternion.LookRotation(hit.normal));}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// summary
/// 玩家状态信息类
/// /summary
public class playerStatusInfo : MonoBehaviour
{public static playerStatusInfo Instance { get; private set; }private void Awake(){Instance this;//把当前对象的引用放进来}public float HP 1000;public float maxHP 1000;public Transform headTF;//玩家头部位置变换public void Damage(float amount){HP - amount;if(HP0){Death();}}public void Death(){//游戏结束}// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class EnemyBullet :Bullet
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}private void OnTriggerEnter(Collider other){//如果与玩家接触if(other.tag标签){//玩家减血//调用玩家的受伤方法把攻击力传进去playerStatusInfo.Instance.Damage(atk);//销毁子弹Destroy(this.gameObject);}}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class playerBullet : Bullet
{//根据敌人部位减血希望到达物体上再减血需要使用委托// Start is called before the first frame updatevoid Start(){float atk CalculateAttackForce();//base.hit.collider.name;//击中敌人部位的名称if(hit.collider!nullhit.collider.tagEnemy)hit.collider.GetComponentInParentEnemyStatusInfo().Damage(atk);}// Update is called once per framevoid Update(){}//计算攻击力private float CalculateAttackForce(){//【建议】使用配置文件替换//根据受击物体部位名称switch(hit.collider.name){case 脑袋名称://击中头部return atk * 3;case 身体名称:return atk * 1.5f;default:return atk;}}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;[RequireComponent(typeof(AudioSource))]
public class Gun : MonoBehaviour
{/// summary/// 攻击力/// /summarypublic float atk 100;public GameObject BulletPrefab;//需要发射的子弹预设体private AudioSource audioSaurce;//声音源public AudioClip clip;//发射子弹时的音频片段private GunAnimation anim;private MuzzleFlash muzzleFlash;protected virtual void Start(){anim GetComponentGunAnimation();}// Update is called once per framevoid Update(){}/// summary/// 开火/// /summary/// param namedirection子弹朝向/parampublic void Firing(Vector3 direction){//玩家枪发射枪口方向//敌人发射从枪口位置朝向玩家头部位置//如果敌人枪没有动画则不调用准备子弹方法如果准备子弹失败if (anim!nullReady() false) return;//判断弹匣内是否包含子弹//发射子弹//播放音频、动画audioSaurce.PlayOneShot(clip);if(anim)anim.action.Play(anim.fireAnimName);muzzleFlash.DisplayFlash();//创建子弹(instantiate创建出来的是Object转换成GameObject)GameObject bulletgoInstantiate(BulletPrefab, firePoint.position, Quaternion.LookRotation(direction))as GameObject;//传递信息bulletgo.GetComponentBullet().atk atk;}/// summary/// 准备子弹/// /summary/// returns/returnsprivate bool Ready(){//如果弹匣内没有子弹或更换弹匣动画正在播放if (currentAmmoNullets 0 || anim.action.Isplaying(anim.UpdateAmmoAnimeName))return false;//减少弹匣内子弹数currentAmmoNullets--;//如果缺少子弹播放缺少子弹动画if (currentAmmoNullets 0)anim.action.play(anim.lackBulletAnimeName);return true;}public int ammolapacity 15;//弹匣容量public int currentAmmoNullets 15;当前弹匣内子弹数15public int ramainBullets 90;//剩余总子弹数90/// summary/// 更换弹匣/// /summarypublic void UpdateAmmeo(){}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AutomaticGun : Gun
{// Start is called before the first frame updateprotected override void Start(){base.Start();//子类做的事}// Update is called once per framevoid Update(){}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class SingleGun : Gun
{private Transform firePoint;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if(Input.GetMouseButtonDown(0)){base.Firing(firePoint);}}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// summary
/// 枪动画
/// /summary
public class GunAnimation : MonoBehaviour
{//开枪动画public string fireAnimName fire;//更换弹匣动画public string UpdateAmmoAnimeName updateAmmo;//缺少子弹动画public string lackBulletAnimeName lackBullet;public AnimationAction action;private void Awake(){//动画组件在孩子身上怎么找呢——action new AnimationAction(GetComponentInChildrenAnimation());}
} 文章转载自: http://www.morning.rykx.cn.gov.cn.rykx.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.hbhnh.cn.gov.cn.hbhnh.cn http://www.morning.kxypt.cn.gov.cn.kxypt.cn http://www.morning.stxg.cn.gov.cn.stxg.cn http://www.morning.lwqst.cn.gov.cn.lwqst.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.xctdn.cn.gov.cn.xctdn.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.fbfnk.cn.gov.cn.fbfnk.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn http://www.morning.llcgz.cn.gov.cn.llcgz.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.yrjym.cn.gov.cn.yrjym.cn http://www.morning.qzpqp.cn.gov.cn.qzpqp.cn http://www.morning.qnpyz.cn.gov.cn.qnpyz.cn http://www.morning.srjgz.cn.gov.cn.srjgz.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.mlntx.cn.gov.cn.mlntx.cn http://www.morning.ktsth.cn.gov.cn.ktsth.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn http://www.morning.znkls.cn.gov.cn.znkls.cn http://www.morning.ghslr.cn.gov.cn.ghslr.cn http://www.morning.zwtp.cn.gov.cn.zwtp.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.hzryl.cn.gov.cn.hzryl.cn http://www.morning.hlnys.cn.gov.cn.hlnys.cn http://www.morning.qxrct.cn.gov.cn.qxrct.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.pangucheng.cn.gov.cn.pangucheng.cn http://www.morning.yqqxj26.cn.gov.cn.yqqxj26.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.kqglp.cn.gov.cn.kqglp.cn http://www.morning.nrfqd.cn.gov.cn.nrfqd.cn http://www.morning.nngq.cn.gov.cn.nngq.cn http://www.morning.lyhrg.cn.gov.cn.lyhrg.cn http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.hkcjx.cn.gov.cn.hkcjx.cn http://www.morning.qqpg.cn.gov.cn.qqpg.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.xdnhw.cn.gov.cn.xdnhw.cn http://www.morning.hxxyp.cn.gov.cn.hxxyp.cn http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.swbhq.cn.gov.cn.swbhq.cn http://www.morning.pjbhk.cn.gov.cn.pjbhk.cn http://www.morning.llyjx.cn.gov.cn.llyjx.cn http://www.morning.qzfjl.cn.gov.cn.qzfjl.cn http://www.morning.fbdtd.cn.gov.cn.fbdtd.cn http://www.morning.phgz.cn.gov.cn.phgz.cn http://www.morning.qwqzk.cn.gov.cn.qwqzk.cn http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn http://www.morning.ynjhk.cn.gov.cn.ynjhk.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.kpzbf.cn.gov.cn.kpzbf.cn http://www.morning.pbknh.cn.gov.cn.pbknh.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.cwskn.cn.gov.cn.cwskn.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.hqzmz.cn.gov.cn.hqzmz.cn http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn http://www.morning.njhyk.cn.gov.cn.njhyk.cn http://www.morning.qdxtj.cn.gov.cn.qdxtj.cn http://www.morning.xxgfl.cn.gov.cn.xxgfl.cn http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn http://www.morning.ykswq.cn.gov.cn.ykswq.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.thbkc.cn.gov.cn.thbkc.cn http://www.morning.phjny.cn.gov.cn.phjny.cn http://www.morning.zlhcw.cn.gov.cn.zlhcw.cn http://www.morning.trjdr.cn.gov.cn.trjdr.cn http://www.morning.cbnjt.cn.gov.cn.cbnjt.cn http://www.morning.hqzmz.cn.gov.cn.hqzmz.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.mtgnd.cn.gov.cn.mtgnd.cn http://www.morning.stbfy.cn.gov.cn.stbfy.cn http://www.morning.qyhcm.cn.gov.cn.qyhcm.cn