Hi, I need a bit of help.
I generate a level and have destroyable blocks in it as well as ai characters that are set up with raycasts onto the solids layer to check different things, like if there is a platform next to them then they can walk left or if not walk right.
I’ve since added the ability to destroy the solids. (platforms and wall blocks).
I get null reference exceptions now from the characters raycasts once a blocks been destroyed (I’m pretty sure that’s whats causing it). I’ve tried real hard to solve this but now don’t know what to do. My raycast script is:
isPlatLeft = Physics2D.Raycast (new Vector2 (transform.position.x - 1.5f, transform.position.y), new Vector2 (-0.5f, -1), 8f, moveMask);
I’ve got just the walls and platforms and ladders set on the moveMask.
This is where I get the nullreference error:
// check if a platform is under the player and off to the left.
if (laddCheckLeft) {
if (laddCheckLeft.collider.tag != null) {
if (laddCheckLeft.transform.tag == "PLATFORM" || laddCheckLeft.transform.tag == "LaddCollider" || laddCheckLeft.transform.tag == "SOLID") {
// int rane = Random.Range (0, 40);
nowOffLadder = false;
//if (rane == 1) {
laddPlatToLeft = true;
//}
} else {
wasOnLadder = true;
laddPlatToLeft = false;
}
} else {
wasOnLadder = true;
laddPlatToLeft = false;
}
} else {
wasOnLadder = true;
laddPlatToLeft = false;
}
Everything worked fine until I started destroying blocks.
As you can see I’ve tried to stop it from happening but not sure what to do now and whats going on.
Can someone help PLEASE???