Что я делаю на своем уровне, таймер отсчитывает от 50 до 0, используя Time.deltaTime, это отлично работает. теперь на скрипте PlayerControl, когда я беру монету, я хочу, чтобы таймер добавлялся на 3 секунды. Мой код ниже.Добавление секунд на мой таймер
// Это PlayerControl, когда я забираю объект PlusOrb.
public class PlayerCTRL : MonoBehaviour
{
public Text timerText;
public TimerCount timerScript;
public Image DamagedOverlay;
public float speed;
public Text CountText;
private int count;
public GameObject TakeDamage;
public Text scoreText;
public TEMPLE_score scoreScript;
public TEMPLE_GlobalSettings globalSettings;
void Start()
{
CountText.text = CoinCounter.ToString();
playerLife = 3;
count = 0;
SetCountText();
playerAS = GetComponent<AudioSource>();
timerScript = GetComponent<TimerCount>();
damaged = false;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("PlusOrb"))
{
Destroy(other.gameObject);
count = count + 1;
SetCountText();
//score
scoreScript.myscore += 2;
scoreText.text = scoreScript.myscore.ToString();
//timer
timerScript.timer + 3f;// this is the problem i am having
PlayerPrefs.SetInt("CoinCount", PlayerPrefs.GetInt("CoinCount") + 1);
}
}
}
// Это сценарий таймера.
public class TimerCount : MonoBehaviour
{
public Text TimeText;
public float timer1 = 50;
float SceneTimer = 0;
TEMPLE_GlobalSettings globalSettings;
public Sprite lives0;
public GameObject Gore;
public PlayerCTRL PlayerController;
int ouch;
void Start()
{
timer1 = 50;
}
void Update()
{
this.GetComponent<Text>().text = timer1.ToString("F0");
timer1 -= Time.deltaTime;
print(timer1);
if (timer1 < 1)
{
timer1 = 0;
PlayerController.playerLife = 0;
SceneTimer += Time.deltaTime;
//if (SceneTimer > 2)
//{
//SceneManager.LoadScene("TEMPLE");
//}
}
}
void GameOver()
{
GameObject thisGore = Instantiate(Gore, transform.position, transform.rotation) as GameObject;
thisGore.GetComponent<ParticleSystem>().Play();
GameObject.Find("Lives").GetComponent<Image>().sprite = lives0;
Destroy(gameObject);
}
}
yer Вот что я пробовал, я думал, что это сработает, но оно все еще не работает. спасибо человеку за ваш ответ. –
Что не работает? Не говорите, что это не работает. Скажите нам, что именно не работает. – Programmer
Я пробовал их все, и теперь его таймер отображает красную строку timerScript.timer = timerScript.timer + 3f; или timerScript.timer + = 3f; –