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

丽水做网站威海哪家做网站好

丽水做网站,威海哪家做网站好,用vs网站开发,网站开发代理江苏版权声明#xff1a; 本文原创发布于博客园优梦创客的博客空间#xff08;网址#xff1a;http://www.cnblogs.com/raymondking123/#xff09;以及微信公众号优梦创客#xff08;微信号#xff1a;unitymaker#xff09;您可以自由转载#x… 版权声明 本文原创发布于博客园优梦创客的博客空间网址http://www.cnblogs.com/raymondking123/以及微信公众号优梦创客微信号unitymaker您可以自由转载但必须加入完整的版权声明雪人兄弟游戏开发过程 场景搭建 1.将Map地图拖入场景 2.创建一个ground空对象给这个对象添加一些Collider 2D 组件把这些Collide2D覆盖到地图可以行走的地方创建以个wall空对象给这个对象添加两个Collider 2D组件把这两个 Collide2D 覆盖到地图的两侧。 创建主角 1.创建hero对象给其一张主角的图片精灵给hero对象添加Rigidbody2D和Collider 2D组件使其可以进行物理运动和碰撞行为 2. 创建动画控制器编辑一些主角行为的的动画再用动画控制器进行控制 3. 添加HeroMove脚本通过编辑代码使主角可以移动和跳跃 //Update时通过射线检测判断是否可以跳跃RaycastHit2D hit Physics2D.Linecast(this.transform.position, t.position, 1 LayerMask.NameToLayer(ground));//Debug.DrawLine(this.transform.position, t.position);// t.position//print((bool)hit);if (Input.GetButtonDown(Jump) hit){jump true;}··· //FixedUpdatebool speed false; //触发动画的布尔变量float h Input.GetAxis(Horizontal);if (h ! 0){speed true;}Vector2 force new Vector2(h * moveForce, 0);//限制移动速度if (Mathf.Abs(rb.velocity.x) maxSpeed){GetComponentAnimator().SetBool(Speed, speed);rb.AddForce(force);}if (Mathf.Abs(rb.velocity.x) maxSpeed){rb.velocity new Vector2(Mathf.Sign(rb.velocity.x) * maxSpeed, rb.velocity.y);}//动画方向转变if (h 0){var s this.transform.localScale;s.x Mathf.Abs(-s.x);this.transform.localScale s;}else if (h 0){var s this.transform.localScale;s.x -Mathf.Abs(-s.x);this.transform.localScale s;}//跳跃if (jump){GetComponentAnimator().SetTrigger(jump);rb.AddForce(Vector2.up * jumpForce);jump false;} 4.让主角可以发射子弹 1. 制作子弹预制体 , 2.给hero添加一个子节点Gun作为生成子弹的点并添加脚本控制子弹的发射和行为。 void Update () {if (Input.GetButtonDown(Fire1)){this.transform.parent.gameObject.GetComponentAnimator().SetTrigger(Shoot);var rocket Instantiate(rocketPrefab);rocket.transform.position this.transform.position;if (this.transform.parent.localScale.x 0){rocket.transform.rotation Quaternion.Euler(0, 0, 0);rocket.GetComponentRigidbody2D().velocity new Vector2(speed, 0);}else{rocket.transform.rotation Quaternion.Euler(0, 0, 180);rocket.GetComponentRigidbody2D().velocity new Vector2(-speed, 0);}}} 创建敌人: 1.创建一个monsters空对象为了确定敌人生成的位置 2. 创建monster对象给其一张敌人的图片精灵给monster对象添加Rigidbody2D和Collider2D组件使其可以进行物理运动和碰撞行为并把它做成预制体。 3. 添加Monster脚本通过编辑代码使敌人可以移动和跳跃 public class Monster : MonoBehaviour {// public float speed 3; private float MonsterMoveForce 0.8f; //速度//private float MonsterMaxSpeed 0.5f; //限制速度public float monsterJumpForce 600f; // 2.8f;private bool monsterJump false;private Transform topCheck;private Transform frontCheck;private Transform downCheck;int h;private int hp 1;public GameObject snowball;public void Start(){topCheck transform.Find(topCheck);frontCheck transform.Find(frontCheck);downCheck transform.Find(DownCheck);}public void Update(){if (hp 0){Vector2 s this.transform.position;hp 0;Destroy(this.gameObject);GameObject g Instantiate(snowball);g.transform.position s;return;}}public void FixedUpdate(){// 跳跃 RaycastHit2D hit1 Physics2D.Linecast(topCheck.position, this.transform.position, 1 LayerMask.NameToLayer(ground));RaycastHit2D hit2 Physics2D.Linecast(downCheck.position, this.transform.position, 1 LayerMask.NameToLayer(ground));RaycastHit2D hit Physics2D.Linecast(frontCheck.position, this.transform.position);h Random.Range(0, 100);Rigidbody2D rb this.transform.gameObject.GetComponentRigidbody2D();Debug.DrawLine(this.transform.position, topCheck.position);Debug.DrawLine(this.transform.position, downCheck.position);Debug.DrawLine(this.transform.position, frontCheck.position);if (hit hit.transform.gameObject.tag wall || hit.transform.gameObject.tag destroyer){Vector3 s this.transform.localScale;//s.x -s.x;this.transform.localScale s;}else if (hit2 hit hit.transform.gameObject.tag ground){monsterJump true;}else{ //随机方向 if (h 2){Vector3 s this.transform.localScale;s.x -s.x;this.transform.localScale s;}}//移动 Vector2 x new Vector2(-this.transform.localScale.x * MonsterMoveForce, rb.velocity.y);rb.velocity x;this.gameObject.GetComponentAnimator().SetTrigger(move);//跳跃if (hit1 hit2 h 3){monsterJump true;}if (monsterJump){rb.AddForce(Vector2.up * monsterJumpForce);monsterJump false;}}public void OnCollisionEnter2D(Collision2D collision){if (collision.gameObject.tag ground){this.gameObject.GetComponentAnimator().SetTrigger(ground);}if (collision.gameObject.tag bullet){hp--;}}public void OnCollisionExit2D(Collision2D collision){if (collision.gameObject.tag ground){this.gameObject.GetComponentRigidbody2D().velocity new Vector2(0, 0);this.gameObject.GetComponentAnimator().SetTrigger(groundl);}}} 创建雪球: 1. 创建snowball对象给其一张默认的图片精灵给snowball对象添加Rigidbody2D和lColider2D组件使其可以进行物理运动和碰撞行并把它做成预制体。 2.给snowball对象添加脚本通过编辑代码添加状态机使雪球状态可以切换。 public class Snowball : MonoBehaviour {StateMachineSnowball stateMachine new StateMachineSnowball();public Sprite snowball1;public Sprite snowball2;public Sprite snowball3;public GameObject monster;public Transform frontCheck;public GameObject[] props;public GameObject balldestory;// Use this for initialization//雪球状态public class SnowballStateB : StateSnowball{public float explodeTime 0;public bool gun false;public float gunForce 3f;float dir;public override void Enter(Snowball e){e.gameObject.GetComponentSpriteRenderer().sprite e.snowball1; //获的图片e.gameObject.GetComponentAnimator().SetTrigger(snowball1);e.frontCheck e.transform.Find(frontCheck);e.gameObject.layer LayerMask.NameToLayer(snowball);}public override void Update(Snowball e){//雪球没滚时隔 6 个时间点恢复成版雪球if (gun false){explodeTime Time.deltaTime;if (explodeTime 6){explodeTime 0;e.stateMachine.ChangeState(new SnowballStateA());return;}}else if (gun){Rigidbody2D rb e.gameObject.GetComponentRigidbody2D();rb.freezeRotation false;Vector2 v new Vector2(dir * gunForce, rb.velocity.y);// rb.AddForce(v);rb.velocity v;Collider2D[] enemies Physics2D.OverlapCircleAll(e.transform.position, 0.05f, 1 LayerMask.NameToLayer(monster));foreach (Collider2D a in enemies){Vector2 s a.gameObject.transform.position;Destroy(a.gameObject);GameObject prop Instantiate(e.props[Random.Range(0, e.props.Length)]);prop.transform.position s;}}}public override void OnCollisionStay2D(Snowball e, Collision2D collision){ContactPoint2D[] a collision.contacts;if (gun false){if (collision.gameObject.tag player collision.gameObject.transform.FindChild(Gun).GetComponentGun().isFire){// dir -GameObject.Find(hero).transform.localScale.x;gun true;dir -collision.transform.localScale.x;}}}public override void OnCollisionEnter2D(Snowball e, Collision2D collision){if (gun false){if (collision.gameObject.tag snowball){gun true;dir -collision.transform.localScale.x;}}if (gun){if (collision.gameObject.tag wall || collision.gameObject.tag snowball){dir -dir;}if (collision.gameObject.tag player){//TODO//雪球带着主角走//transform.SetParent//设置父节点 //collision.transform.SetParent(e.transform);//collision.transform.position e.transform.position;//torque //旋转}}if (collision.gameObject.tag destroyer){e.gameObject.GetComponentAnimator().SetTrigger(destrayer);}}public override void Exit(Snowball e){}}//半雪球状态public class SnowballStateA : StateSnowball{public float explodeTime 0;int hp 0;public override void Enter(Snowball e){e.gameObject.GetComponentSpriteRenderer().sprite e.snowball2;e.gameObject.GetComponentAnimator().SetTrigger(snowball2);e.gameObject.layer LayerMask.NameToLayer(monster);hp 2;}public override void Update(Snowball e){print(hp);if (hp 0){e.stateMachine.ChangeState(new SnowballStateB());return;}explodeTime Time.deltaTime;if (explodeTime 5 hp 0){explodeTime 0;e.stateMachine.ChangeState(new SnowballState());return;}}public override void Exit(Snowball e){}public override void OnCollisionEnter2D(Snowball e, Collision2D collision){if (collision.gameObject.tag bullet){hp--;}}}//monster被攻击状态public class SnowballState : StateSnowball{public float explodeTime 0;Vector3 s;public int hp 0;public override void Enter(Snowball e){//取得图片精灵e.gameObject.GetComponentSpriteRenderer().sprite e.snowball3;e.gameObject.GetComponentAnimator().SetTrigger(snowball3);e.gameObject.layer LayerMask.NameToLayer(monster);hp 3;}public override void Update(Snowball e){print(hp);if (hp 0){e.stateMachine.ChangeState(new SnowballStateA());hp 0;return;}explodeTime Time.deltaTime;print(explodeTime);//经过多少时 if (explodeTime 4 hp 0){explodeTime 0;hp 0;s e.gameObject.transform.position;GameObject g Instantiate(e.monster);g.transform.position s;Destroy(e.gameObject);return;}}public override void OnCollisionEnter2D(Snowball e, Collision2D collision){if (collision.gameObject.tag bullet){hp--;}}}void Start(){stateMachine.Init(this, new SnowballState());}// Update is called once per framevoid Update(){}public void FixedUpdate(){stateMachine.Update();}public void OnCollisionEnter2D(Collision2D collision){stateMachine.OnCollisionEnter2D(this, collision);}public void OnCollisionStay2D(Collision2D collision){stateMachine.OnCollisionStay2D(this, collision);}public void Destory(){Instantiate(balldestory);Destroy(this.gameObject);}} 创建道具 1.添加道具预制体. 2.雪球撞到敌人时敌人死亡在敌人死亡的地方随机生成一种道具。 3.主角吃到道具增加属性或者加分。 过关判定 判断场景中没有敌人并且没有雪球并且没有道具就过关了。转载于:https://www.cnblogs.com/raymondking123/p/8424673.html
http://www.zqtcl.cn/news/82781/

相关文章:

  • 湛江市seo网站设计报价营销网站怎么做合适
  • 成都网站建设方案人与马做的网站
  • 外贸网站建设推广智慧校园学生管理系统
  • 品牌网站建设服务商漯河网站制作公司
  • 在济南什么人想做网站扬州百度推广公司
  • 网站需求流程图下载用的网站怎么做
  • 青岛大学网站建设如何做网站卡密
  • 商业网站 技术今天的新闻大事
  • 红酒网站制作苏州园区人力资源中心
  • 怎么做购物网站系统文本php 英文网站模板
  • 有什么做糕点的视频网站怎么把视频制作成链接
  • 深圳网站制作大运软件小镇wordpress 炫酷博客
  • 网站开发者不给源代码怎么办怎样黑网站
  • 做百度推广一个月多少钱唐山seo推广公司
  • 茅台酒网站建设方案个人网站当企业网站用
  • seo超级外链工具seo 重庆
  • 网站备案ip地址公司网站建设进度
  • 爱站网主要功能wordpress 底部 时间
  • 做网站需要什么材料音乐设计网站推荐
  • 泉州app网站开发价格天津vi设计公司
  • 做调查问卷权威网站手机app开发培训课程
  • 标准论坛网站建设linux网站环境
  • win8怎么建设网站WordPress查询登录记录
  • 网站关键字怎么优化怎么做网站下单
  • 全球最大的设计网站申请域名 建设网站
  • 宁夏网站开发北京网站建站系统平台
  • 哪些域名商可以自助wordpress深圳网站优化费用
  • 中职高一网站建设试题个人定做衣服店
  • 服务器与网站吗dedecms医院网站
  • 新手学做网站看什么书网站临时会话