Some scripts stop working on build but work in editor?
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.
@SweetInsanityArts How do they stop working, they are just ignored? Throw errors? What happens? Also, for what platform are you building, is it PC or Android or...?
Building for PC
They are ignored, I'm guessing? I run into the colliders that are supposed to trigger the script and the character slows down a bit so the collider is definitely still there but it doesnt take any damage, health bar doesnt go down, sound isnt played.
Is there a way to see errors while playing the actual game like the console in the Unity editor?
@SweetInsanityArts Here's some info on that. Viel Glück.
Answer by tormentoarmagedoom · Feb 05, 2020 at 12:20 PM
Hello. Scripts seems correct, the problem is not here. You should know first what is happening exactly. As @JPhilipp says, What is happening? Do something to know what parts of the code are beeing called, like create a text in a canvas to "say" and "check" when the code reach some parts of the code, so you can know for example if the trigger part code is beeing called while the game is built and running. MAybe is a collider-detection problem. Are the objects moving very fast? Then Change Collision detection to Continous from the inspector.
Good luck"
Your answer
Follow this Question
Related Questions
how do i add script folder to final build 0 Answers
Is it possible to output different builds which share the same Data folder? 0 Answers
Massive File Header Build Size 1 Answer
The referenced script on this Behaviour is missing - on any new script 0 Answers
UnityEditor.Animations API in a build 2 Answers