I tried a lot, but I can´t get my head around this one. It happens, as soon as the playercharacter dies and there´s bullet clones still on the screen.
I understand, that it happens, because of the player not being part anymore of the game when he dies.
But what can I do about it?
I tried some fuzzy null statements. I tried public Gameobject target instead of player (works for the exception. The projectile gets instantiated in the wrong way though…)
public class EnemyProjectile : MonoBehaviour {
private LevelManager theLevelManager;
private Rigidbody2D myRigidbody;
public float speed;
public PlayerControllerWobble player;
public int damageToGive;
public GameObject impactEffect;
// Use this for initialization
void Start () {
theLevelManager = FindObjectOfType<LevelManager>();
myRigidbody = GetComponent<Rigidbody2D>();
player = FindObjectOfType<PlayerControllerWobble>();
if(player.transform.position.x < transform.position.x)
{
speed = -speed;
}
}
Do I get that whole process totally wrong? If so, why?
Maybe. It will clear out some things for me… I don´t even need a corrected code. I´m also happy with a hint/tipp on how to solve this.
I don´t exactly know why… but apparently it worked, even though I tried something similar before?
Is the order of the statement important? Mine was like the opposite way around with the null statement in the end.
Edit: How do you mark an answer as the correct one?
Yes, the order of the statement is important. The checks are processed from left to right. If you do the transform check first it will throw an exception.
And I don’t think that the forum gives you the possibility to mark an answer as correct. But I could be wrong.