Character doesn't trigger collissions

I’m using a character controller I customized myself. My character has a rigid body, a sphere collider and a box collider for good measure. My trigger has a rigid body (tried without it), a sphere collider checked to trigger, a box collider checked to trigger. I’ve tried everything and nothing triggers my debug log.

the script for detection the trigger in c# is

using UnityEngine;
using System.Collections;

public class sandStorm : MonoBehaviour {
private string theCollider;
//private Collider other;
//Collision collision;


	void Start()
	{
		Debug.Log("Starting SandStorm");
	}
	
	void Update ()
	{
		
	}
		void onTriggerEnter (Collider other)
	{
//		theCollider = other.tag;
//		if (theCollider == "Player")
//		{
//			audio.Play();
//			audio.loop = true;
			Debug.Log ("playing sound");
//		}
	}
	
	void onTriggerExit(Collider other)
	{
//			theCollider = other.tag;
//		if (theCollider == "Player")
//		{
			Debug.Log ("Stop Playing Sound");
//			audio.Stop ();  //this is only necessary because the audio file is too long to let finish its loop
//			audio.loop = false;
//		}
	}
	
}

2 Answers

2

Make sure the “!” icon is checked on your Debug log, or you won’t be alerted to those Debug.Log commands.

Here is a test code I made that works for me:

using UnityEngine;
using System.Collections;

public class deathZone : MonoBehaviour {

	void OnTriggerEnter(Collider other)
	{
		Debug.Log("Cheese sticks");
	}
}

I have a Box Collider on my Player, without “Is Trigger” checked, and a RigidBody set to “Discrete Collisions”.
My trigger has only a Box Collider, with “Is Trigger” checked.

Everything works fine there. (script set to “Collider other” only for testing purposes. You likely will want to set it to “Collider Player”, and set your Player character’s “Tag” to “Player”, so that other colliders in the scene don’t trigger the script you’re making.)

edit: Also, how are you using this script? What is the goal of it? Usually you want the script to be on a trigger object that activates the function when your player enters the collider space.

Make sure you spelled “OnTriggerEnter” correctly (including caps).
The most simple grammar errors cause the biggest problems in unity :wink:

If that doesnt work, try doing this:

void OnTriggerEnter(Collider other)
{
if(other.gameObject.name == "[your object name]")
{
Debug.Log("I ate a penguin")
}
}