I'm using C# for my game and the Detonator package. For some reason the below code is telling me that the Detonator object namespace cannot be found. I have it attached to a gameobject with a Detonator script also attached. Can anyone shed some light?
public void OnTriggerEnter(Collider other) {
GameObject go = other.gameObject;
Detonator dn = go.GetComponent<Detonator>();
dn.Explode();
}
I'm not sure what's causing the error, but just to make sure you didn't miss anything, here are the steps you should have followed to use the Detonator package.
- Import the package using Assets->Import Package. Make sure everything is checked.
If the import worked, you should see several new directories, specifically Prefab Examples and System.
- From the System directory in the Project tab, drag/drop a Component Script called Detonator. Not the Prefab called Detonator - Base, which would be a GameObject, not a Component.
One simple way to test it without relying on a Collider, is to create a new public GO variable on your Script object, and drag/drop the Object with the Detonator script to it:
public GameObject someBomb;
void OnMouseUp() {
Detonator foo = someBomb.GetComponent<Detonator>();
if (foo == null)
Debug.Log("wups no foo");
else {
Debug.Log("foo booming");
foo.Explode();
}
}
I always like to check found Components for null. Especially for Scripts - if there are errors in them, they don't compile, and references to them get nulled, leaving you wondering why a working Script suddenly broke...
I solved the problem. The error was due to not having my Camera object tagged as Main Camera. Hopefully this will save some grief for others in the future.
Thanks for the help!