- Home /
Disable Box Collider on Tagged Object
I'm building a simple game and one of the mechanics are pickups/collectables that do certain things. I have a few things in my scene. Player, pickup (FireProof) some fire, obstacles and a finish line. I'm trying to make it so when the player collides with the object tagged "FireProof" it removes the box colliders on any game objects tagged as "Fire" but I don't know how to do it.
using UnityEngine;
using System.Collections;
public class Lvl1GameLogic : MonoBehaviour {
public bool IsFireProof;
void Awake(){
IsFireProof = false;
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.tag == "FireProof")
{
Destroy(col.gameObject);
IsFireProof = true;
}
if(col.gameObject.tag == "Fire")
{
if(IsFireProof == true) {
// disable box collider
}
else {
Application.LoadLevel(1);
}
}
if(col.gameObject.tag == "Obstacle")
{
Application.LoadLevel(1);
}
if(col.gameObject.tag == "Finish")
{
Application.LoadLevel(2);
}
}
}
Any help is appreciated.
Answer by maccabbe · May 12, 2015 at 09:01 PM
Depending on intended behaviour you can use
col.collider.SetActive(false);
or
GameObject.Destroy(col.collider);
Answer by zviaz · May 12, 2015 at 09:14 PM
This is what eventually worked
if(col.gameObject.tag == "Fire")
{
if(IsFireProof == true) {
Destroy(col.collider);
}
else {
Application.LoadLevel(1);
}
}
Your answer
Follow this Question
Related Questions
Ammo crate collision 2 Answers
Help With Colliders 3 Answers
Creating a Asteroid health script 5 Answers
Fade texture on collision/trigger with certain tag or layer? 2 Answers
Gun swap through collision 1 Answer