I have a script that is suppose to display test on the screen and play an animation when the player walks through a box collider only it doesn’t work. When the player walks through the collider nothing is played. I have several other scripts that are almost identical to this and they all work perfectly so I don’t understand the problem.
This is the script…
using UnityEngine;
using System.Collections;
public class LightScene3 : MonoBehaviour {
public int wait;
public GUIStyle text;
string message = " ";
//GUI Box
void OnGUI() {
GUI.Label((new Rect(600,400,200,200)),message ,text);
}
//Displaying text
IEnumerator OnTriggerEnter(Collider otherObjective){
if (otherObjective.tag == "Player") {
message = "Insert Text Here";
GetComponent<UnityEngine.Animation> ().Play ("TeacherMonster");
yield return new WaitForSeconds(wait);
message = "Insert More Text Here";
yield return new WaitForSeconds(wait);
}
}
}
What part of your script were you expecting to display "test" on the screen? Same answer as for all collision-doesn't-work questions: - You need colliders on both objects, one marked as Is Trigger - You need a Rigidbody on at least one object - Get rid of the tag test, and just use Debug.Log to confirm that OnTriggerEnter is being called. You can print the name of the triggering Gameobject - it may not be what you think it is.
– tanoshimi