0
PlayerがPowerUpにヒットしたときに、タイマーに10秒を追加します。 私はキャンバスに追加されたタイマースクリプトを持っています。Unity3dはカウントダウンタイマーに時間を追加しますか?
これはtimer.cs ..です
をだから私は(私はPlayerPrefs.SetInt
を使用)パワーアップスクリプトに時間を追加しようとしましたが、タイマースクリプトのPlayerPrefs.GetInt
は常に真であるので、すぐに私のカウンターの上にいくつかの時間を追加します。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class timer : MonoBehaviour
{
public Text textTime;
public float second = 0;
private int minutes = 1;
public int second2 = 0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
textTime.text = minutes + ":" + second2;
second -= Time.deltaTime;
second2 = (int)second;
if (second < 1)
{
minutes--;
second += 60f;
}
if (minutes == 0 && second2 == 1)
{
PlayerPrefs.SetInt("Gameover", 0);
Application.LoadLevel("gameover");
}
if ((PlayerPrefs.GetInt("timer")) == 1)
{
second2 += 10;
}
}
}
そして、これがパワーアップスクリプトです:提供あなたのコードスニペットで
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour
{
void Start() {
}
Update is called once per frame
void Update() {
}
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
PlayerPrefs.SetInt("timers", 1);
gameObject.SetActive(false);
}
}
はあなたには、いくつかの基本的なデバッグを試みたことがありますか? 'PlayerPrefs.GetInt(" timer ")'値をコンソールに 'minutes'と' second2'だけでなく印刷してみてください。 –