Unity资产商店示例游戏代码不工作 - 在Unity中工作完美,但在Android中不工作。

问题描述 投票:-1回答:0

我坚持使用无尽跑者的代码,这是资产商店的示例代码。(https:/assetstore.unity.compackagesessentialstutorial-projectsendless-runner-sample-gam-87901。)

我的游戏在Unity中工作得很完美,但当我将apk导出到Android Mobile时,第二场景无法正常加载,无法工作。

有完全相同的问题 与这个问题。

我发现 "ThemeDatabase.loaded "和 "CharacterDatabase.loaded "在Unity中都是true,但在Android中是false。

LoadoutState.cs

public override void Tick()
{
    if (!runButton.interactable)
    {
        bool interactable = ThemeDatabase.loaded && CharacterDatabase.loaded;
        if(interactable)
        {
            runButton.interactable = true;
            runButton.GetComponentInChildren<Text>().text = "Run!";

            //we can always enabled, as the parent will be disabled if tutorial is already done
            tutorialPrompt.SetActive(true);
        }
    }

    if(m_Character != null)
    {
        m_Character.transform.Rotate(0, k_CharacterRotationSpeed * Time.deltaTime, 0, Space.Self);
    }

    charSelect.gameObject.SetActive(PlayerData.instance.characters.Count > 1);
    themeSelect.gameObject.SetActive(PlayerData.instance.themes.Count > 1);
}

"interactiveable "在Android中是false。(bool interactable = ThemeDatabase.loaded && CharacterDatabase.loaded;) 所以我无法启动游戏,代码无限期运行。

CharacterDatabase.cs如下。

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

/// <summary>
/// This allows us to store a database of all characters currently in the bundles, indexed by name.
/// </summary>
public class CharacterDatabase
{
    static protected Dictionary<string, Character> m_CharactersDict;

    static public Dictionary<string, Character> dictionary {  get { return m_CharactersDict; } }

    static protected bool m_Loaded = false;
    static public bool loaded { get { return m_Loaded; } }

    static public Character GetCharacter(string type)
    {
        Character c;
        if (m_CharactersDict == null || !m_CharactersDict.TryGetValue(type, out c))
            return null;

        return c;
    }

    static public IEnumerator LoadDatabase()
    {
        if (m_CharactersDict == null)
        {
            m_CharactersDict = new Dictionary<string, Character>();

            yield return Addressables.LoadAssetsAsync<GameObject>("characters", op =>
            {
                Character c = op.GetComponent<Character>();
                if (c != null)
                {
                    m_CharactersDict.Add(c.characterName, c);
                }
            });

            m_Loaded = true;
        }
    }
}
unity3d
© www.soinside.com 2019 - 2024. All rights reserved.