我正在制作一个加载场景。我没有使用加载栏。我打算使用 png 图像。我的脚本用于加载 png 图像。我没有任何错误。 png 已导入到元素中。这是我得到的代码:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class djsi : MonoBehaviour {
public png;
// Use this for initialization
void Start () {
img.gameObject.SetActive(false);
}
// Update is called once per frame
IEnumerator abc()
{
img.gameObject.SetActive(true);
yield return new WaitForSeconds(1.5f);
SceneManager.LoadSceneAsync("scene1");
}
void Update () {
}
}
最佳答案
据我所知,您需要一个静态图像作为加载屏幕,在这种情况下,这应该让您了解您需要做什么,请记住,此脚本需要附加到 UI Image 对象以工作。
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class djsi : MonoBehaviour
{
public Sprite png;
Image Comp;
// Use this for initialization
void Start()
{
Comp = gameObject.GetComponent<Image>();
Comp.sprite = png;
Comp.enabled = false;
StartCoroutine(LoadScene());
}
// Update is called once per frame
IEnumerator LoadScene()
{
Comp.enabled = true;
SceneManager.LoadSceneAsync("scene1");
yield return new WaitForSeconds(1.5f);
Comp.enabled = false;
}
void Update()
{
}
}
关于css - 如何在 unity3d 上加载 png 图像并使用加载场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39443010/