【发布时间】:2019-12-08 23:03:07
【问题描述】:
所以我正在尝试制作一款文字冒险游戏,并且我想在出现特定对话时更改游戏背景。我在开始时已经有一个黑色图像,并且想在整个游戏过程中更改它。
我为对话制作了一个可编写脚本的对象。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
[CreateAssetMenu(menuName = "Dialogue")]
public class Dialogue : ScriptableObject
{
[TextArea(10, 14)] [SerializeField] string dialogueText;
[SerializeField] string hintText;
[SerializeField] Dialogue[] nextDialogue;
[SerializeField] public Image background; // Thats the old Image that I want to change
[SerializeField] public Sprite newBackground; // Thats the new Background I want to put in Image
public bool dialogueHolder;
public void Awake()
{
if (background != null)
{
background.sprite = newBackground; // this code is not working
}
}
public string getHintText()
{
return hintText;
}
public string GetDialogue()
{
return dialogueText;
}
public Dialogue[] GetNextDialogue()
{
return nextDialogue;
}
【问题讨论】:
-
你似乎没有清楚地勾勒出你被困在哪里或到目前为止你已经尝试过什么