using UnityEngine;
using System.Collections;
public class TestC1 : MonoBehaviour {
private Quaternion qua1,qua2;
const int UP = 0;
const int DOWN = 1;
private int state = UP;
// Use this for initialization
void Start () {
//qua1 = Quaternion.Euler(120f,transform.rotation.eulerAngles.y,transform.rotation.eulerAngles.z);
qua2 = Quaternion.Euler(-85f,transform.rotation.eulerAngles.y,transform.rotation.eulerAngles.z);
qua1 = Quaternion.Euler(120f,transform.rotation.eulerAngles.y,transform.rotation.eulerAngles.z);
}
// Update is called once per frame
void Update () {
//transform.rotation = Quaternion.Lerp(transform.rotation,qua1,Time.deltaTime * 0.2f);
switch(state){
case UP:
transform.rotation = Quaternion.Lerp(transform.rotation,qua1,Time.deltaTime * 0.2f);
if(transform.rotation.eulerAngles.x >= 85f){
state = DOWN;
}
break;
case DOWN:
transform.rotation = Quaternion.Lerp(transform.rotation,qua2,Time.deltaTime * 1.2f);
break;
}
}
}
using UnityEngine;
using System.Collections;
public class TestA3 : MonoBehaviour {
// Use this for initialization
void Start () {
Destroy(gameObject,3.0f);
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
public class TestA2 : MonoBehaviour {
float x,z;
int speed = 5;
public int HP = 100;
string colName = "";
// Use this for initialization
void Start () {
}
// 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);
}
void OnCollisionEnter(Collision col){
//print (col.collider.name);
colName = col.collider.name;
if(colName ==("Sphere(Clone)")){
//print ("HP--");
HP--;
}
}
//Sphere(Clone)
void OnGUI(){
GUILayout.Label("HP:"+HP,GUILayout.Height(200));
}
}
using UnityEngine;
using System.Collections;
public class TestA1 : MonoBehaviour {
GameObject camera;
public Transform newobject,bulletTrans;
float i11 = 0;
float i22 = 0.0f;
// Use this for initialization
void Start () {
camera = GameObject.Find("Main Camera");
}
// Update is called once per frame
void Update () {
//transform.Translate(Vector3.left*Time.deltaTime*0.5f);
i11 = Vector3.Distance(transform.position,camera.transform.position);
//print(i11);
//Debug.Log(i11);
transform.LookAt(camera.transform);
transform.Translate(Vector3.forward*Time.deltaTime*1.5f);
if(i11<20.0f){
if(i22>2){
shot();
i22 = 0;
}else{
i22 = i22 + Time.deltaTime;
}
}
}
void shot(){
Transform n = Instantiate(bulletTrans,this.transform.position,this.transform.rotation)as Transform;
Vector3 fwd = this.transform.TransformDirection(Vector3.forward);
n.rigidbody.AddForce(fwd*2800);
}
}
//x = Input.GetAxis("Horizontal")*Time.deltaTime * speed;
//z = Input.GetAxis("Vertical")*Time.deltaTime * speed;
//this.transform.Translate(x,0,z);
/*
Transform n = Instantiate(newobject,transform.position,transform.rotation)as Transform;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
n.rigidbody.AddForce(fwd*2800);
*/