Hi, I’m trying to create a script that runs at the very beginning of my game that sets up classes and variables for me to be able to use anywhere in the game. I want to call for example global.money and when I pick up money to add to that saved total. And I want to set up my Character classes at the very beginning of the game so I can create my 5 characters’ list of stats. In my game I want to be able to switch between characters on the fly, and depending on what character is being controlled I want to be able to call and edit that character’s list of variables like health, attack, so on. But every time I try something in this Initialize code, I get errors. Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class global
{
public enum CharID
{
Blank = 0,
VoidChar = 1,
FireChar = 2,
EarthChar = 3,
WindChar = 4,
WaterChar = 5,
}
public Character VoidChar;
public Character FireChar;
public Character EarthChar;
public Character WindChar;
public Character WaterChar;
}
public class Character
{
public int id; // Which character is it
public bool available; // Is character unlocked
public string name; // Character name
public int trueMaxHP; // Character true max HP
public int maxHP; // Character max HP
public int HP; // Character current HP
public int trueMaxMP; // Character true max MP
public int maxMP; // Character max MP
public int MP; // Character MP
public float healthCorrupt; // Character health corrupt
public float magicCorrupt; // Character magic corrupt
public int attackPower; // Character attack power
public int defensePower; // Character defense power
public int magicPower; // Character magic power
public int jumpHeight; // Character jump height
public int runSpeed; // Character run speed
public int weight; // Character weight
public bool[] unlockedSpells; // Array for unlocked spells
public int[] spellWheel; // Array for bound spells
}
public class Begin : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//Set up characters
global.VoidChar = new Character
{
};
//Go to first room
SceneManager.LoadScene("EarthTemple");
}
}
Help! Thanks.