玩家启动并收集燃料罐,燃料存放在更大的油箱中,然后加载下一张地图。收集的燃料设置为 0。在第二张地图中,收集了燃料,但当你存放它时,分数将被覆盖,而不是添加到。
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public static ScoreManager instance;
//script refs
GasTransfer gt;
LevelLoader levelLoader;
//text refs
public Text ScoreText;
public Text StoredFuel;
//bools ints
public int collectedfuel = 0;
private int score;
public int storedFuel;
public bool fuelDelivered;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else if (instance != null)
Destroy(gameObject);
}
public void Start()
{
gt = FindObjectOfType<GasTransfer>();
levelLoader = FindObjectOfType<LevelLoader>();
}
// Update is called once per frame
public void Update()
{
ScoreText.text = collectedfuel.ToString();
if (Input.GetKey(KeyCode.F) && gt.isAtpump)
{
score = collectedfuel = storedFuel;
storedFuel = collectedfuel;
StoredFuel.text = score.ToString();
fuelDelivered = true;
}
if (fuelDelivered)
{
gt.pressF.SetActive(false);
levelLoader.LoadNextLevel();
}
}
public void AddFuel()
{
collectedfuel += 5;
}
public void RemoveFuel()
{
collectedfuel -= 5;
if(collectedfuel < 0)
collectedfuel = 0;
}
}
看了几个视频,教程,unity教程。这就是我走到这一步的方式。我只是找不到合适的单词组合来添加到现有分数中。