- Home /
How can I enlarge the box collider when a prefab is active
I'm trying to enlarge a box collider when a prefab is spawned so it gives damage to the play but I don't want the box collider there when the prefab isnt active.
This is the code so far:
{
public BoxCollider Flame;
public GameObject MegalothFlameManager;
// Use this for initialization
void Start ()
{
Flame = Flame.GetComponent <MegalothFlameManager>();
}
// Update is called once per frame
void Update ()
{
if (MegalothFlameManager = true); <<stuck here <<<
{
Flame.size = new Vector3 (1f, 1f, 1f);
Flame.center = new Vector3 (1f, 1f, 1f);
}
}
}
Im stuck on the "if (MegalothFlameManager = true);" Ive come across tutorials but they're all ontriggerenter and I don't want that.
Any suggestions?
Answer by agarcia115 · Jun 08, 2018 at 10:31 AM
Right now you're trying to compare two supposed game objects, i think that you should change your expression probably to this:
if (MegalothFlameManager != null){
Flame.enabled = true; //(With this you enable the collider)
Flame.size = new Vector3 (1f, 1f, 1f);
Flame.center = new Vector3 (1f, 1f, 1f);
}else{
Flame.enabled = false;
}
That will check everyframe if your object is active or not, and if it is it will set active the collider. If it's not it will be disabled. If you want to instantiate your prefab when the player crosses or something like that, check distance between the object and your player so if it is less than "X" your collider will be active
I think that should work if I actually understood your problem!
Your answer
Follow this Question
Related Questions
Turing GameObjects On and Off again. 4 Answers
Setting thrown object to kinematic after hitting target? 1 Answer
Is there a way to find other's components using OnTriggerEnter? 1 Answer
accessing script components from external objects 2 Answers
Can I access a script OnTrigger WITHOUT using getcomponent? 1 Answer