OnTriggerEnter issues

I made a bonfire prefab that starts off with the fire disabled, but I want to make it so when the player hits it with a torch the fire gets re-enabled. The disabling part works fine, but the re-enabling part doesn’t. It’s supposed to be when a trigger with the “Fire” tag enters the bonfire’s hitbox (which is pretty big), it enables the particles and sound.

Here’s some code, hopefully it will help:

using UnityEngine;
using System.Collections;

public class LightCampfires : MonoBehaviour
{
	public GameObject fire;

	void Start()
	{
		fire.SetActive(false);
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.gameObject.CompareTag("Fire"))
			fire.SetActive(true);
	}
}

The fire variable is linked to the fire particles (and light). The torch that the player is holding has a large cube trigger around it with the Fire tag, but it still won’t activate the bonfire.

Perhaps “fire.enabled” would do the trick ? Or how about using “fire.particeStuff.emit” instead of setActive ?

I might be wrong, but doesn’t “setActive(false)” disable the object in which case you all the scripts on the bonFire stop working ? (.enabled might do the same if I’m not mistaken)

So perhaps use .enabled for the light and .emit for the particles?

fire.light.enabled = true;
fire.particleEmitter.emit = true;

Also, you could try doing it the other way around… the bonFire could have a trigger on it and the torch a rigidBody… Triggers only seem to work if a rigidbody is moving into them… or if you have some specific reason to keep those things the way they are you could use

transform.Translate(new Vector3(0,0,0));

on the bonFire rigidBody… (same idea as always, rigidBody has to move so that the Trigger can detect it)

which wouldn’t be so nice from a coding perspective, but I guess that it should work…

You need to add Rigidbody to the trigger.

You also might want to check IsKinematic