Ok、now、begin!
今天同一整理学习了太空大战的开发、现在来做个总结:
1、首先是背景的生成和管理:
星空 直接建一张plane,再贴上星星的图片。
火星 mars.png (生成一个Material), 设置 shader —> Transparent—>cutout—>diffuse
建好之后保存场景,计作为Level0,(也就是关卡1)
2、开始创建主角飞机,
它有这么几个属性:
移动速度:m_speed = 1,
生命值: m_life = 10 ,
前后左右方向的移动:movev = 0 , moveh = 0
再定义了一个子弹的附件 Transform m_rocket (用来发射子弹,计:一定要在子弹对象实例化后,关联文件)
飞机的移动: this.transform.Translate(moveh,0,movev);
发射子弹: Instantiate(m_rocket,m_tranform.position,m_transform.ratation)
主角Player的代码:
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public Transform m_rocket;
public float m_speed = 5;
public float rocketLaunchTime = 0;
public float m_life = 10;
public AudioClip m_shootClip;
public AudioSource m_audio;
public Transform m_explosionFX;
// Use this for initialization
void Start () {
m_audio = this.audio;
}
// Update is called once per frame
void Update () {
float movev = 0;
float moveh = 0;
if (Input.GetKey (KeyCode.W)) {
movev = -m_speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.S)) {
movev = m_speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.A)) {
moveh = m_speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.D)) {
moveh = -m_speed * Time.deltaTime;
}
rocketLaunchTime = rocketLaunchTime - Time.deltaTime;
if (rocketLaunchTime <= 0) {
rocketLaunchTime = 0.1f;
if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton (0)) {
Instantiate(m_rocket,this.transform.position,this.transform.rotation);
m_audi