I’m only into the Number Wizard UI for Unity 2d, and its the first course I’ve taken, so please be gentle. I have tried to add some additional functionality to the game wherein I have scriptable objects that give the wizard some flavor text, and have a unique image assigned to each text bit. The code works within Unity, except it throws a null reference exception, and when built for WebGL it throws a memory access out of bounds error when you click the “start” button to move into the game. Can someone help me with this in a new-dude-to-this speak? Can that even be done? Thanks in advance for your help!
The Scriptable objects script BMchat.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[CreateAssetMenu(menuName = "chat")]
public class BMchat : ScriptableObject
{
[TextArea(14, 14)] [SerializeField] string bmChat;
[SerializeField] Sprite bmImage;
public string Chat()
{
return bmChat;
}
public Sprite Sprite()
{
return bmImage;
}
}
My MainGame.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class MainGame : MonoBehaviour
{
[SerializeField] int maximum;
[SerializeField] int minimum;
[SerializeField] TextMeshProUGUI guessText;
[SerializeField] Text textLink;
[SerializeField] BMchat[] chatmad;
[SerializeField] Image imagelink;
Sprite bmSprite;
string angrychat;
int arraysize;
int playerGuess;
void Start()
{
maximum = maximum + 1;
NextGuess();
textLink.text = ("This is your number or I will burn everything you have ever loved.");
for (arraysize = 0; arraysize < chatmad.Length; arraysize++);
}
public void Higher()
{
minimum = playerGuess;
NextGuess();
AngryChat();
}
public void Lower()
{
maximum = playerGuess;
NextGuess();
AngryChat();
}
public void NextGuess()
{
playerGuess = Random.Range(minimum, maximum);
guessText.text = playerGuess.ToString();
}
private void AngryChat()
{
int randomizer = Random.Range(0, arraysize);
angrychat = chatmad[randomizer].Chat();
bmSprite = chatmad[randomizer].Sprite();
textLink.text = angrychat;
imagelink.sprite = bmSprite;
}
}
And my SceneController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneController : MonoBehaviour
{
public void NextScene()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentScene + 1);
}
public void ReturnScene()
{
SceneManager.LoadScene(0);
}
}
The Maingame script is attached to an empty object and the object references are filled as such