using UnityEngine;
using System.Collections;
public class TestD3 : MonoBehaviour {
public Transform newobject;
int speed = 5;
int i1 = 0;
int i2 = 0;
int i3 = 0;
float i12 = 1;
float i22;
// Use this for initialization
void Start () {
i22 = Random.Range(1,5);
}
// Update is called once per frame
void Update () {
if(i1> 500){
transform.Translate(speed*Time.deltaTime,0,0);
if(i2> 500){
i1 = 0;
}
i2++;
}else{
transform.Translate(-speed*Time.deltaTime,0,0);
i1++;
i2 = 0;
}
if(i12>i22){
shot();
i12 = 0;
}else{
i12 = i12 + Time.deltaTime;
}
}
void shot(){
Transform n = Instantiate(newobject,transform.position,transform.rotation)as Transform;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
n.rigidbody.AddForce(fwd*2800);
}
}
using UnityEngine;
using System.Collections;
public class TestD2 : MonoBehaviour {
int i1 = 0;
string s1 = "";
public GUIText GT2;
// Use this for initialization
void Start () {
i1 = 99;
GT2.text = "大方块生命值:"+i1;
}
// Update is called once per frame
void Update () {
//transform.Translate(Vector3.forward * Time.deltaTime);
transform.Rotate(Vector3.up* Time.deltaTime*150);
}
void OnTriggerEnter(Collider col){
print (col.collider.name);
}
void OnCollisionEnter(Collision col){
//print (col.collider.name);
s1 = col.collider.name;
if(s1.Equals("qiu1(Clone)")){
//print ("OK");
i1--;
//print(i1);
GT2.text = "大方块生命值:"+i1;
if(i1<0)
{
Destroy(gameObject);
}
}
}
}
using UnityEngine;
using System.Collections;
public class TestD1 : MonoBehaviour {
int speed = 5;
float i1,x,z;
public Transform cubeT;
public Transform newobject;
public GUIText GT1;
// Use this for initialization
void Start () {
//GT1 = GameObject.Find("/GT1");
//GT1.text = "AAA";
}
// Update is called once per frame
void Update () {
i1 = Vector3.Distance(transform.position,cubeT.position);
//print (i1);
GT1.text = "距离:"+i1.ToString();
x = Input.GetAxis("Horizontal")*Time.deltaTime * speed;
//z = Input.GetAxis("Vertical")*Time.deltaTime * speed;
this.transform.Translate(x,0,z);
if(Input.GetKey(KeyCode.Q))
{
transform.Rotate(0,-25*Time.deltaTime,0,Space.Self);
}
if(Input.GetKey(KeyCode.E))
{
transform.Rotate(0,25*Time.deltaTime,0,Space.Self);
}
if(Input.GetKey(KeyCode.Space)){
//print ("fire");
shot();
}
}
void OnCollisionEnter(Collision col){
print (col.collider.name);
}
void shot(){
Transform n = Instantiate(newobject,transform.position,transform.rotation)as Transform;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
n.rigidbody.AddForce(fwd*2800);
}
}