开发路线:
1,游戏背景(连续播放)
2,添加主角
3,设置游戏主角的动画
4,添加两种子弹并设置子弹的运动 5,添加三种子弹
设置子弹的自动生成和运动
6,添加两种奖励物品
设置奖励物品的自动生成和运动 7,设置主角的控制
7.1检测手指触摸
7.2问题:防止主角飞出屏幕 8,设置Tag
添加子弹和敌人的碰撞
9,设计敌人 0 1 2 震动动画和爆炸效果
10,添加脚本GameManager做游戏的控制
11,统计分数

  

1,新建项目,导入资源,平台匹配;

2,背景循环(一般是2/3个背景精灵切换);

A. 精灵Sprite :Pixels Per Unit 是精灵的尺寸在unity之后的换算问题

栗子:图片高度为852像素,导入后显示的为8个单位

B. 建立一个空节点做父节点,在每个背景上添加脚本,BackgroundScroll

C.脚本; BackgroundScroll.cs

private static float moveSpeed = 3.0f;

void Start () {

}

void Update () {

//move down

this.transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);

//limit

Vector3 pos = transform.position;

if(pos.y <= -8.52f)

{

this.transform.position = new Vector3(pos.x, pos.y + 8.52f * 2, pos.z);

}

}

3.制作主角动画:(序列帧实现动画)

A.拖拽第一张精灵图片,层次:渲染的顺序

B.一般2D游戏设置:

C. 分别设置不同的层级:一般0-;数字越小先渲染,然后会被后渲染的遮挡住;

D. 设置主角为character,后添加脚本 Hero;

脚本:using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Hero : MonoBehaviour {

//标志位,控制动画播放

public bool animation = true;

//每秒播放帧数 五遍动画 一个动画播放2帧

public int frameCountPerseconds = 10;

//计时器

public float timer = 0;

//sprites

public Sprite[] sprites;

//2

private SpriteRenderer spriteRenderer;

void Start () {

spriteRenderer = this.GetComponent<SpriteRenderer>();

}

void Update () {

if (animation)

{

timer += Time.deltaTime;

//每帧所用事件 1f/frameCountPerseconds

int frameIndex = (int)(timer / (1f / frameCountPerseconds));

int frame = frameIndex % 2;//取值0,1

//this.GetComponent<SpriteRenderer>().sprite = sprites[frame];//消耗性能

spriteRenderer.sprite = sprites[frame];

}

}

}

E.子弹;character层;添加脚本Bullet:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Bullet : MonoBehaviour {

public float moveSpeed = 2;

void Start () {   }

void Update () {

transform.Translate(Vector3.up * Time.deltaTime * moveSpeed);

//limit

if(transform.position.y >=4.3f)

{

Destroy(this.gameObject);

}

}

}

F.在Hero对象下添加对应位置的空节点放置

脚本Gun: 放置不同的子弹预制

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Gun : MonoBehaviour {

public float rate = 0.2f;

public GameObject bullet;

public void Fire()

{

GameObject.Instantiate(bullet, transform.position, Quaternion.identity);//第三个参数:旋转角度,四元素的一个(无旋转的)静态变量

}

public void OpenFire()

{

InvokeRepeating("Fire", 1, rate);

}

void Start () {

OpenFire();

}

}

G.敌人,三种类型添加脚本Enemy,之后挂载 修改对应的hp和move_speed

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Enemy : MonoBehaviour {

public int hp = 1;

public float speed = 2;

public int score = 100;

void Update () {

this.transform.Translate(Vector3.down * speed * Time.deltaTime);

if(this.transform.position.y <= -5.6f)

{

Destroy(this.gameObject);

}

}

}

H.奖励:两种 脚本Award:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Award : MonoBehaviour {

public int type = 0;//0 gun 1 explose

public float speed = 1.5f;

void Update () {

this.transform.Translate(Vector3.down * speed * Time.deltaTime);

if(this.transform.position.y <= -4.5f)

{

Destroy(this.gameObject);

}

}

}

  1. 上述诸多对象做成预制,添加空节点,命名Spawn(用于生成对象)

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Spawn : MonoBehaviour {

public GameObject enemy0Prefab;

public float enemy0Rate = 0.5f;

void Start () {

InvokeRepeating("createEnemy0", 1, enemy0Rate);

}

public void createEnemy0()

{

//随机pos.x

float pos_x = Random.Range(-2.15f, 2.15f);

GameObject.Instantiate(enemy0Prefab,new Vector3(pos_x,transform.position.y,transform.position.z),Quaternion.identity);

}

}

unity仿微信飞机大战项目的更多相关文章

  1. 【一】仿微信飞机大战cocos2d-x3.0rc1

    參考 [偶尔e网事] 的 [cocos2d-x入门实战]微信飞机大战  cocos2dx 2.0版本号,偶尔e网事他写的很具体,面面俱到,大家很有必要看下.能够通过以下链接跳转: cocos2d-x入 ...

  2. Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现

    看到cocos2d-x推出了3.1版本号,真是每月一次新版本号,速度. 另一个好消息就是http://cn.cocos2d-x.org/上线了,祝贺!啥时候把我的视频和教程放上去呢?!! . 视频下载 ...

  3. 用DIV+Css+Jquery 实现的旧版微信飞机大战。

    用jquery 实现的旧版微信飞机大战. 以前一直都是做后台和业务逻辑,前端很少去做, 现在个小游戏. 方向键控制方向,Ctrl 键 放炸弹(当然你的有炸弹,哈哈)! 主要都是用div+Css实现的, ...

  4. 用Javascript模拟微信飞机大战游戏

    最近微信的飞机大战非常流行,下载量非常高. 利用JS进行模拟制作了一个简单的飞机大战[此源码有很多地方可以进行重构和优化] [此游戏中没有使用HTML5 任何浏览器都可以运行]. 效果图: 原理:利用 ...

  5. [Unity3D]Unity3D游戏开发之飞机大战项目解说

    大家好,我是秦元培,欢迎大家继续关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 首先感谢大家对我博客的关注,今天我想和大家分享的是一个飞机大战的项目.这是一个比較综合的 ...

  6. 500行代码,教你用python写个微信飞机大战

    这几天在重温微信小游戏的飞机大战,玩着玩着就在思考人生了,这飞机大战怎么就可以做的那么好,操作简单,简单上手. 帮助蹲厕族.YP族.饭圈女孩在无聊之余可以有一样东西让他们振作起来!让他们的左手 / 右 ...

  7. [置顶] 【cocos2d-x入门实战】微信飞机大战之四:飞机登场咯

    转载请表明地址:http://blog.csdn.net/jackystudio/article/details/11757175 昨天收到了电子工业出版社寄过来的<cocos2d-x游戏开发之 ...

  8. 【开源】SpringBoot&Netty实现仿微信网页版项目更新

    阅读本文约“2.3分钟” 项目更新啦!V1.3.0 还记得那个聊天室的小项目吗? SpringBoot 加 Netty 实现聊天室 没错,这次已经完整进行了版本的替换,酥酥聊天室! 基于原项目的改动, ...

  9. 用Swift语言和Sprite Kit复制微信飞机大战游戏

    先上GitHub链接: https://github.com/songrotek/PlaneWar.git 接下来略微解说一下! 这个程序还有点Bug,见谅! 1 说明 游戏採用了Sprite kit ...

随机推荐

  1. 关于The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum...

    今天将项目迁移到另一台笔记本,进行build出现以下问题,导致build失败 The specified Android SDK Build Tools version (26.0.2) is ign ...

  2. alpha冲刺10/10

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺倒计时之10(匆匆而过) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 答辩演练 版本演示视频拍摄 接下来的计划 ...

  3. 【C#】WebApi 添加过滤器,实现对请求参数和响应内容的日志记录

    filter的介绍 filter在Web API中经常会用到,主要用于记录日志,安全验证,全局错误处理等:Web API提供两种过滤器的基本类型:actionfilterattribute,excep ...

  4. 【AtCoder】ARC074

    ARC 074 C - Chocolate Bar 直接枚举第一刀横切竖切,然后另一块要求如果横切分成\(H / 2\)竖切分成\(W/2\)即可 #include <bits/stdc++.h ...

  5. websocket/dwebsocket 实现前后端的实时通信

    1.  用bottle框架,自己写一个服务端实现: 转载   :http://www.linuxyw.com/813.html 功能:用websocket技术,在运维工具的浏览器上实时显示远程服务器上 ...

  6. fillder--模拟弱网

    ##设置路径## Rules--Performemnts---Silamte Mordem Speeds 弱网原理 Rules—>Cutomize Rules打开CustomRules.js 文 ...

  7. spring cloud (二、服务注册安全demo_eureka)

    spring cloud (一.服务注册demo_eureka) 加强服务的安全性,我们接下来加上访问的账号密码: 首先需要添加对应的依赖 <!--账号密码认证依赖--> <depe ...

  8. pyqt text browser 设置文本

    pyqt text browser 设置文本 setHtml(u"Html") setPlainText(u"纯文本") setText(u"文本\n ...

  9. springboot配置log4j

    maven 配置jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  10. JAVA项目中常用的异常处理情况

    1.数学运算异常( java.lang.arithmeticexception) 程序中出现了除以零这样的运算就会出这样的异常,对这种异常,大家就要好好检查一下自己程序中涉及到数学运算的地方,公式是不 ...