using UnityEngine;
using System.Collections;
public class TestB4 : MonoBehaviour {
//敌人生成脚本
public Transform m_enemy;
protected float m_timer = 5;
protected Transform m_transform;
// Use this for initialization
void Start () {
m_transform = this.transform;
}
// Update is called once per frame
void Update () {
m_timer -= Time.deltaTime;
if(m_timer<=0)
{
m_timer = Random.value * 15.0f;
if(m_timer<5)
m_timer = 5;
Instantiate(m_enemy,m_transform.position,Quaternion.identity);
}
}
}
using UnityEngine;
using System.Collections;
public class TestB3 : MonoBehaviour {
//Player主角脚本
public int HP = 100;
public int score = 0;
public Transform bulletTran;
private float uv,uh;
float x,z;
public int speed = 5;
private bool bool1,bool2;
float m_rocketRate = 0;
// Use this for initialization
void Start () {
bool1 = false;
bool2 = false;
}
// Update is called once per frame
void Update () {
x = Input.GetAxis("Horizontal")*Time.deltaTime * speed;
z = Input.GetAxis("Vertical")*Time.deltaTime * speed;
this.transform.Translate(x,0,z);
m_rocketRate -= Time.deltaTime;
if(m_rocketRate <= 0 ){
if(Input.GetKey(KeyCode.Space)){
//print ("shot");
m_rocketRate = 0.5f;
shot();
}
}
}
void OnGUI(){
GUILayout.Label("HP:"+HP+" \nSCORE:"+score,GUILayout.Width(100));
/*
if(GUILayout.Button("LEFT",GUILayout.Height(50))){
x+=Time.deltaTime*speed;
}
if(GUILayout.Button("RIGHT",GUILayout.Height(50))){
x-=Time.deltaTime*speed;
}*/
if(GUILayout.Button("FIRE",GUILayout.Height(50))){
shot();
}
if(GUI.Button(new Rect(0,Screen.height-100,100,100),"LEFT"))
{
if(bool1){
x=0;
bool1=false;
}else{
bool2=true;
}
x-=Time.deltaTime*speed;
}
if(GUI.Button(new Rect(Screen.width-100,Screen.height-100,100,100),"RIGHT"))
{
if(bool2){
x=0;
bool2=false;
}else{
bool1=true;
}
x+=Time.deltaTime*speed;
}
}
void shot(){
Instantiate(bulletTran,this.transform.position,this.transform.rotation);
}
public void setScore(int iScore){
score = iScore;
}
public int getScore(){
return score;
}
public void setHP(int iHP){
HP = iHP;
}
public int getHP(){
return HP;
}
}
using UnityEngine;
using System.Collections;
public class TestB2 : MonoBehaviour {
//子弹
public float m_speed = 10f;
public float m_liveTime = 3f;
public float m_power = 1.0f;
protected Transform m_transform;
// Use this for initialization
void Start () {
Destroy(gameObject,9.0f);
}
// Update is called once per frame
void Update () {
this.transform.Translate(new Vector3(0,0,m_speed * Time.deltaTime));
}
void OnTriggerEnter(Collider other){
if(other.tag.CompareTo("enemy")!=0)
return;
Destroy(gameObject);
}
}
using UnityEngine;
using System.Collections;
public class TestB1 : MonoBehaviour {
public float m_life = 1.0f;
public float m_speed = 2.5f;
protected float m_rotSpeed = 30f;
protected float m_timer = 1.5f;
protected Transform m_transform;
TestB3 testB3;
string tmp1 = "";
GameObject player;
// Use this for initialization
void Start () {
player = GameObject.Find("player");
testB3 = player.GetComponent<TestB3>();
transform.LookAt(player.transform);
}
// Update is called once per frame
void Update () {
UpdateMove();
//transform.Translate(new Vector3(0,0,-0.1f));
//transform.Translate(Vector3.forward*Time.deltaTime*2.5f);
}
void UpdateMove(){
m_timer -= Time.deltaTime;
if(m_timer<=0){
m_timer = 3;
m_rotSpeed = -m_rotSpeed;
}
this.transform.Rotate(Vector3.up,m_rotSpeed*Time.deltaTime,Space.World);
this.transform.Translate(new Vector3(0,0,m_speed*Time.deltaTime));
}
void OnTriggerEnter(Collider other){
//Debug.Log("OnTriggerEnter:"+other.collider.name);
tmp1 = other.collider.name;
if(tmp1=="wall1")
{
Destroy(this.gameObject);
}
if(other.tag.CompareTo("bullet")==0){
//print ("hit bullet");
Destroy(this.gameObject);
int i2 = testB3.getScore();
i2++;
testB3.setScore(i2);
}
if(other.tag.CompareTo("Player")==0){
//print ("hit bullet");
Destroy(this.gameObject);
int i1 = testB3.getHP();
i1--;
testB3.setHP(i1);
}
}
void OnCollisionEnter(Collision col){
Debug.Log("OnCollisionEnter:"+col.collider.name);
}
}