Unity3d打飞机(三) 敌机和空投的生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InEnemy : MonoBehaviour {
//实例化的位置
public Transform enemyLocation;
//实例敌机
public Transform enemySmall;
public Transform enemyMiddle;
public Transform enemyBig;
//空投
public Transform superBullet;
public Transform bomb;
// Use this for initialization
void Start () {
//循环调用某个方法 方法名 开始后多长时间开始调用 调用间隔
InvokeRepeating ("CreateEnemySamll", 1f, 0.2f);
InvokeRepeating ("CreateEnemyMiddle", 2f, 2f);
InvokeRepeating ("CreateEnemyBig", 3f, 4f);
InvokeRepeating ("CreateSuperButtle", 5f, 5.5f);
InvokeRepeating ("CreateBomb", 5.5f, 6f);
}
// Update is called once per frame
void Update () {
}
//小飞机
void CreateEnemySamll(){
var en = Instantiate (enemySmall);
en.position = new Vector3 (Random.Range(-2.8f, 2.8f), enemyLocation.position.y, 0f);
}
//中飞机
void CreateEnemyMiddle(){
var en = Instantiate (enemyMiddle);
en.position = new Vector3 (Random.Range(-2.8f, 2.8f), enemyLocation.position.y + 1f, 0f);
}
//大飞机
void CreateEnemyBig(){
var en = Instantiate (enemyBig);
en.position = new Vector3 (Random.Range(-2.8f, 2.8f), enemyLocation.position.y + 2f, 0f);
}
//超级子弹
void CreateSuperButtle(){
var sb = Instantiate (superBullet);
sb.position = new Vector3 (Random.Range(-2.8f, 2.8f), enemyLocation.position.y + 1.5f , 0f);
}
//炸弹
void CreateBomb(){
var b = Instantiate (bomb);
b.position = new Vector3 (Random.Range(-2.8f, 2.8f), enemyLocation.position.y + 2.5f , 0f);
}
}