0

在我的游戏计分系统上需要你的帮助吗?我已经在本地测试了游戏,分数运行良好,它可以在不同的场景中显示相同的分数。不幸的是,当我将它构建成 HTML5 WebGL 并将其上传到我的网站时,分数并没有出现在其他场景中。我不确定是什么导致了这个问题,下面是编码:


第一个文件:StaticVar.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StaticVar : MonoBehaviour
{
    public Transform player;
    public static float num = 0;
    // Update is called once per frame
    // void Update()
    // {
    //     num = player.position.z;
    // }

    public void OnCollisionEnter(Collision other) 
    {
        if(other.gameObject.tag != "Hit")
        {
            num++;
            // Debug.Log("Amount of time bumped into walls " + hits);
        }
    }
}

第二个文件:score.cs

using UnityEngine;
using UnityEngine.UI;

public class score : MonoBehaviour
{
    public Transform player;
    public Text scoreText;
    // Update is called once per frame
    void Update()
    {
        scoreText.text = StaticVar.num.ToString("0");   
    }
}
4

0 回答 0