2014年12月9日 星期二

Unity 計時器 Damo

結果呈現:





--------------------------------------------------------------------------------------------
發射物件:

using UnityEngine;
using System.Collections;

public class Fire : MonoBehaviour
{
int timer_i = 0;
public GameObject fireGameonbjcet;
public int fireSw;
// Update is called once per frame
void time4 ()
{
if (fireSw == 1) {
Debug.Log ("1");
timer_i += 1;
Instantiate (fireGameonbjcet, transform.position, transform.rotation);
}
}
void Start ()
{
InvokeRepeating ("time4", 1f, 2f);
}

void OnGUI ()
{
if (Input.GetKeyDown (KeyCode.Alpha1)) {
fireSw = 1;
} else if (Input.GetKeyDown (KeyCode.Alpha2)) {
fireSw = 2;
}
if (fireSw == 2) {
GUI.Label(new Rect(Screen.width/Screen.width, Screen.height/Screen.height, 400 ,50),"請案下數字鍵 1: 自動生產物件");
if (Input.GetMouseButtonDown(0)) {
Instantiate (fireGameonbjcet, transform.position, transform.rotation);
}
}else if(fireSw == 0){
GUI.Label(new Rect(Screen.width/Screen.width, Screen.height/Screen.height, 400 ,50),"請案下數字鍵 1: 自動生產物件,2: 滑鼠左鍵生產物件");
}else if(fireSw == 1){
GUI.Label(new Rect(Screen.width/Screen.width, Screen.height/Screen.height, 400 ,50),"請案下數字鍵 2: 滑鼠左鍵生產物件");
}
}
}

--------------------------------------------------------------------------------------------
物件行為:

using UnityEngine;
using System.Collections;

public class GameobjectTest : MonoBehaviour {
public float speed;
// Update is called once per frame
void Update () {
transform.Translate(-Vector3.forward * Time.deltaTime * speed);
Destroy(gameObject, 2f);
}
}


沒有留言:

張貼留言