【发布时间】:2020-05-02 13:39:51
【问题描述】:
所以我有一个玩家氧气的脚本,它就像一个计时器,当它达到 0 时游戏结束。
我希望玩家能够在我创建的世界中收集氧气,当他们与氧气物体碰撞时,滑块会增加,但不应超过 100。
下面是我的滑块代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class oxygenscript : MonoBehaviour
{
public Slider oxygenbar;
public float oxygen;
public float maxhealth = 1000;
void Start()
{
oxygen = maxhealth;
oxygenbar = GetComponent<Slider>();
oxygenbar.maxValue = maxhealth;
oxygenbar.value = oxygen;
}
void Update()
{
oxygen -= 0.1f;
oxygenbar.value = oxygen;
if (oxygen <= 0)
{
GameManager.Instance.setGameOver();
Time.timeScale = 0;
}
}
}
【问题讨论】:
-
发布您的代码。
-
代码有什么问题?除了氧气损失率基于帧率而不是 time.deltaTime 或其他任何事实之外。
-
当玩家与物体碰撞时如何增加滑块的时间
-
本题与unityscript无关