So im trying to make a Text adventurer game and i want to change the background of the game when a specific dialogue shows up. I already have a black Image at the start and want to change it throughout the game.
I've made a scriptable object for the dialogues.
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;
}