Unity Count Up Timer问题

时间:2016-09-05 21:58:21

标签: javascript unity3d timer

我正在用javascript创建游戏。我有一个很大的问题。在我的一个剧本中,我制作了一个角色(随机时间)。在另一个脚本中,我想在我的角色出现时开始计时计时...这是我目前的代码...

我的问题是计数器没有开始计数......

<小时/> 字符脚本:

//Shoot.js

#pragma strict
var inimigo : GameObject;
var minWait = 5.0;
var maxWait = 20.0;
//static var Shoot : boolean = false;
static var Shoot = false;

function Start () {
    inimigo.SetActive(false);
   Shoot = false;
    Wait();
}

function Update () {
    if (Shoot == true) {
        inimigo.SetActive(true);
    }
    if (Shoot == true && Input.GetMouseButtonDown(0)) {
        Debug.Log("It Worked");
    }
}

function Wait() {
    yield WaitForSeconds(Random.Range(minWait, maxWait));
    Shoot = true;
}

<小时/> 计时器脚本:

//CountUpTimer.js
#pragma strict

private var startTime : float;
private var textTime : String;
private var guiTime: float;
private var minutes : int;
private var seconds : int;
private var fraction : int;
private var textField : UI.Text;

function Start() {
}

function Update () {
    if(Shoot.Shoot == true) {
        startTime = Time.time;
        textField = GetComponent(UI.Text);
    }

    guiTime = Time.time - startTime;
    minutes = guiTime / 60; 
    seconds = guiTime % 60;
    fraction = (guiTime * 100) % 100;
    textTime = String.Format ("{0:00}:{1:00}:{2:00}", minutes, seconds, fraction);

    textField.text = textTime;
}

0 个答案:

没有答案