Yeah, I know; confusing title. I have an OnTiggerEnter in my script and I put a Debug.log to test if it hits something, Yet it doesn’t print the log when the trigger collides with something. What’s even more strange, is that I made a Debug.log further in, testing if it hit a broken terminal that you’re meant to fix, and THAT log comes out fine! It’s really odd. This is the script;
using UnityEngine;
using System.Collections;
public class FireScript : MonoBehaviour
{
public float size;
private GameControllerScript controllerScript;
private GameObject levelController;
private bool isFixed;
private GameObject enemy;
private NewEnemyScript enemyScript;
void Start()
{
isFixed = false;
particleEmitter.maxSize = 0.00f;
levelController = GameObject.FindWithTag("GameController");
controllerScript = levelController.GetComponent<GameControllerScript>();
enemy = GameObject.FindWithTag("Enemy");
enemyScript = enemy.GetComponent<NewEnemyScript>();
collider.enabled = false;
}
void OnTriggerEnter(Collider other)
{
Debug.Log ("Trigger has hit something");//This one doesn't work...
if (other.tag == ("Broken Terminal") isFixed == false)
{
Debug.Log ("Collider has hit terminal");
controllerScript.SendMessage("GameEnding");
isFixed = true;
}
else
{
if(Input.GetKey("b"))
{
if(other.tag == "Enemy")
{
Debug.Log ("enemy got hit");//but this one does! Weird...
enemyScript.SendMessage("ApplyDamage", 1f);
}
}
}
}
void FlameFireUp()
{
audio.Play();
particleEmitter.maxSize = 3.09f;
collider.enabled = true;
}
void FlameFireDown()
{
audio.Stop();
particleEmitter.maxSize = 0.00f;
collider.enabled = false;
}
}
I had a similar problem while working on my turret system. My Enemy cube HAS a rigidbody and while I was moving my Enemy cube around, into and out of my turrets collider all has happy in Unity-ville. This was not the case if I moved my ship that was holding my turret. The OnTriggerEnter NEVER fired.
I don’t know if it’s because I’m moving my objects in the Editor and not via force or if the documentation is incorrect.
You can replicate it as follows:
Cube1 - has collider rigidbody (my Enemy)
Cube2 - has collider (my ship w/turret)
Drop a script on each with OnTriggerEnter
If you move Cube1 into Cube2, both scripts are triggered.
If you move Cube2 into Cube1, neither is called.
It was kind of weird with mine. The doc. said that a Rigidbody can be attached to EITHER collider, but I put one on the receiving end (the broken terminal) and it still didn’t work. Had to put it on the welder. Weird, but at least it works…
Indeed, I just watched (mostly listened to) the roll-a-ball tutorial series and the gist of it was that moving objects that don’t have a rigidbody cause a lot of extra work (constantly updating collision cache) so I’d guess the “golden rule” would be; If it moves, put a rigidbody on it.
Apart from if you want a third person controller. I thought it might be a good idea at first, but then I remembered about the step offset… Hard to do with Rigidbody’s.
Thanks. I kinda feel a bit thick though, as the explanation was fairly simple