I am making a metroidvania game and its going really but when ever i collect a power up i get this error The object of type ‘BoxCollider2D’ has been destroyed but you are still trying to access it. How do i fix it because it works perfectly just how i want it the only thing is i get the error, my code(its attached to my player) CAN ANSWERS BE IN JAVA SCRIPT ONLY:
#pragma strict
var Speed : float = 12;
var Health : float = 100;
//Items and ability variables
var ShowLabelSuperboots : boolean = false;
var ShowLabelLaserblaster : boolean = false;
var ShowLabelMegaBoots : boolean = false;
var ShowLabelGevar : boolean = false;
var Skin : GUISkin;
var AbilityLabelTime : float = 3;
var CollectedGun : boolean = false;
var StopTime : float = 3;
//Bullet variables
public var bulletRight : GameObject;
public var bulletLeft : GameObject;
function Update ()
{
//Jump
if (Input.GetKey (KeyCode.W))
{
transform.Translate(Vector3(0,Speed,0) * Time.deltaTime);
}
//Move left
if (Input.GetKey (KeyCode.A))
{
transform.localScale.x = 1;
transform.Translate(Vector3(-Speed,0,0) * Time.deltaTime);
}
//Move right
if (Input.GetKey (KeyCode.D))
{
transform.localScale.x = 1;
transform.Translate(Vector3(Speed,0,0) * Time.deltaTime);
}
//Shoot right
if (CollectedGun == true){
if(Input.GetKey(KeyCode.RightArrow)) {
Instantiate(bulletRight, transform.position, Quaternion.identity);
}
}
//Shoot left
if (CollectedGun == true){
if (Input.GetKey(KeyCode.LeftArrow)) {
Instantiate(bulletLeft, transform.position, Quaternion.identity);
}
}
}
function OnTriggerEnter2D (other : Collider2D) {
//Super speed power up
if (other.gameObject.tag == "SuperSpeed") {
ShowLabelSuperboots = true;
Speed = Speed + 8;
Destroy(other.gameObject);
yield WaitForSeconds(AbilityLabelTime); ShowLabelSuperboots = false;
}
//Laserblaster power up
if (other.gameObject.tag == "Laserblaster") {
CollectedGun = true;
ShowLabelLaserblaster = true;
Destroy(other.gameObject);
yield WaitForSeconds(AbilityLabelTime); ShowLabelLaserblaster = false;
}
//Megaspeed power up
if (other.gameObject.tag == "MegaSpeed") {
ShowLabelMegaBoots = true;
Destroy(other.gameObject);
Speed = Speed + 10;
yield WaitForSeconds(AbilityLabelTime); ShowLabelMegaBoots = false;
}
//Gevar suit power up
if (other.gameObject.tag == "Gevar") {
ShowLabelGevar = true;
Destroy(other.gameObject);
yield WaitForSeconds(AbilityLabelTime); ShowLabelGevar = false;
}
}
function OnGUI() {
GUI.skin = Skin;
//Label Super Boots
if (ShowLabelSuperboots){
GUI.Label(Rect(100,100,Screen.width,Screen.height),"Super Boots Acquired - These let you move and jump faster");
}
//Label Laserblaster
if (ShowLabelLaserblaster){
GUI.Label(Rect(100,100,Screen.width,Screen.height),"Laser Blaster Acquired - This lets you shoot with the arrow keys");
}
//Label Mega Boots
if (ShowLabelMegaBoots){
GUI.Label(Rect(100,100,Screen.width,Screen.height),"Mega Boots Acquired - These let you move and jump even faster");
}
//Label Gevar Suit
if (ShowLabelGevar){
GUI.Label(Rect(100,100,Screen.width,Screen.height),"Gevar Suit Acquired - Protects you from lava");
}
}