- Home /
This question was
closed Oct 08, 2018 at 08:58 AM by
IMPLOSIONS for the following reason:
I used savedata to save and retrieve the coins value
Question by
IMPLOSIONS · Oct 08, 2018 at 08:28 AM ·
dontdestroyonloadfindobjectoftype
dontdestroyonload breaks findobjectoftype
I have a gamemanager in my game and want coins to persist through levels without having to save and load them all the time. so I have an awake on the gamemanager that looks like this:
public static GameManager manager;
void Awake()
{
if (manager == null)
{
DontDestroyOnLoad(gameObject);
manager = this;
}
else if (manager != this)
{
Destroy(gameObject);
}
}
but when I try to call it using
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Finish")
{
finished = true;
}
if (collision.tag == "HurtPlayer" && !playerInvincable)
{
animator.SetBool("IsHurt", true);
Invoke("ResetHurtAnim", hurtAnimationTime);
FindObjectOfType<GameManager>().HurtPlayer(1);
playerInvincable = true;
Invoke("ResetInvincable", invTime);
}
}
from my player character it creates a null exeption but it doesn't when I comment the first code out
is there a way to fix this
Comment
Follow this Question
Related Questions
FindObjectOfType or FindWithTag 1 Answer
DontDestroyOnLoad() does not seem to be working. 3 Answers
FindGameObjectsWithTag not finding a tagged object 4 Answers
DontDestroyOnLoad duplication. 0 Answers
Next LEVEL Load Problem. 2 Answers