Hi, I have an issue, I destroyed my gameObject “ColToMove” but “if (ColToMove!=null)” is still true. I also have an error console saying that “ColToMove.transform.position” has been destroyed and that I should check if it is not null or not destroy it.
This function ReplaceCube() is called in a OnCollisionExit2D().
Is someone can explain me why “if (ColToMove!=null)” is true ?
thanks
function ReplaceCube(col:Collision2D) {
RandomHightDown=Random.Range(1,3);
if (col.gameObject.tag != "StartCube") {
if (ColToMove!=null) {
if (RandomHightDown==1) {
ColToMove.transform.position = PreviousPosition + CubeEspaceHight;
PreviousPosition += CubeEspaceHight;
}
else if (RandomHightDown==2){
ColToMove.transform.position = PreviousPosition + CubeEspaceDown;
PreviousPosition += CubeEspaceDown;
}
}
ColToMove=col;
}
}