I’m working on my first ever project that has to be handed in next week and it was all running smoothly in the editor but when I export the game, some of the scripts don’t seem to work.
As far as I can tell, the scripts in questions are the ones that control damage & healing.
They’re split into 3 different scripts.
collect.cs
public class collect : MonoBehaviour
{
public int Mana;
public int Gesundheit;
public AudioSource Eat;
public AudioSource Squeak;
private void OnTriggerEnter2D(Collider2D other)
{
GameObject.Find("GAME").GetComponent<GAME>().gesammelt(Mana, Gesundheit);
if (gameObject.tag=="heal")
{
Eat.Play();
gameObject.SetActive(false);
}
if (gameObject.tag == "thorns")
{
Squeak.Play();
}
}
}
values.cs
[CreateAssetMenu(fileName = "Werte", menuName = "Daten/Speicher/Werte")]
public class Werte : ScriptableObject, ISerializationCallbackReceiver
{
public int Mana = 0;
public int Gesundheit = 100;
private int DefaultMana = 100;
private int DefaultGesundheit = 100;
public void OnBeforeSerialize()
{
}
public void resetvalues()
{
Mana = DefaultMana;
Gesundheit = DefaultGesundheit;
}
public void OnAfterDeserialize()
{
Mana = DefaultMana;
Gesundheit = DefaultGesundheit;
}
}
and the GAME.cs to manage it all.
public class GAME : MonoBehaviour
{
//public Text Punkteanzeige;
public Werte Spielstand;
public GameObject rat;
public GameObject explosion;
public RectTransform barFillRT;
private Vector3 barFill;
void Start()
{
barFill = barFillRT.localScale;
}
public void gesammelt(int p, int g)
{
Spielstand.Mana += p;
Spielstand.Gesundheit += g;
Spielstand.Gesundheit = Mathf.Clamp(Spielstand.Gesundheit,0, 100);
barFill.x = Spielstand.Gesundheit/100f;
barFillRT.localScale = barFill;
if (Spielstand.Gesundheit<=0)
{
GameObject exp=Instantiate(explosion, transform.position,transform.rotation);
exp.transform.position = rat.transform.position;
rat.SetActive(false);
StartCoroutine("RestartLevel");
}
}
IEnumerator RestartLevel() {
yield return new WaitForSeconds(3f);
Spielstand.resetvalues();
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Anyone know why those aren’t exported/don’t work in the exported game?
I checked the console but it isnt giving me any errors.