Unity3D
太空大战源码
Enemy的源码:
using UnityEngine;
using ;
[ponentMenu("MyGame/Enemy")]
public class Enemy : MonoBehaviour {
// 速度
public float m_speed = 1;
// 生命
public float m_life = 10;
// 旋转速度
protected float m_rotSpeed = 30;
// 变向间隔时间
protected float m_timer = ;
protected Transform m_transform;
public Transform m_explosionFX;
public int m_point = 10;
// Use this for initialization
void Start () {
m_transform = ;
}
// Update is called once per frame
void Update () {
UpdateMove();
}
protected virtual void UpdateMove()
{
m_timer -= ;
if (m_timer <= 0)
{
m_timer = 3;
//改变旋转方向
m_rotSpeed = -m_rotSpeed;
}
// 旋转方向
(, m_rotSpeed * , );
// 前进
(new Vector3(0, 0, -m_speed * ));
}
void OnTriggerEnter(Collider other)
{
if (("PlayerRocket") == 0)
{
Rocket rocket = <Rocket>();
if (rocket != null)
{
m_life -= ;
if (m_life <= 0)
{
(m_point);
Instantiate(m_explosionFX, , );
Destroy();
}
}
}
else if (("Player") == 0)
{
m_life = 0;
Instantiate(m_explosionFX, , );
Destroy();
}
if (("bound") == 0)
{
m_life = 0;
Destroy();
}
}
}
EnemyRocket的源码:
using UnityEngine;
using ;
[ponentMenu("MyGame/EnemyRocket")]
public class EnemyRocket : Rocket
{
void OnTriggerEnter(Collider other)
{
if (("Player") != 0)
return;
Destroy();
}
}
EnemySpawn敌人生成器:
using UnityEngine;
using ;
[ponentMenu("MyGame/EnemySpawn")]
public class EnemySpawn : MonoBehaviour
{
// 敌人的Prefab
public Transform m_enemy;
// 生成敌人的时间间隔
protected float m_timer = 5;
Unity3D太空大战 来自淘豆网m.daumloan.com转载请标明出处.