Okay, so I’m trying to make an object do a function when it enters a trigger with the tag of “Trap” even thought they both have box colliders and the Trap tagged object’s box collider is set to ‘is trigger’. I’ve used print() to see if the trigger was working but it wasn’t triggered.
using UnityEngine;
using System.Collections;
public class Patrol : MonoBehaviour {
public int NumberOfPoints;
public GameObject enemydeathParticles;
public Transform[] patrolPoints;
public float moveSpeed;
private int currentPoint;
// Use this for initialization
void Start () {
transform.position = patrolPoints[0].position;
currentPoint = 0;
}
// Update is called once per frame
void Update () {
if (transform.position == patrolPoints [currentPoint].position)
{
currentPoint++;
}
if (currentPoint == NumberOfPoints)
{
currentPoint = 0;
}
transform.position = Vector3.MoveTowards (transform.position, patrolPoints [currentPoint].position, moveSpeed * Time.deltaTime);
}
void EnemyDie()
{
Instantiate(enemydeathParticles, transform.position, Quaternion.identity);
print ("An Enemy has died!");
Destroy(gameObject);
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Trap")
{
EnemyDie ();
}
}
}
If you need anymore information, I’m here. Sorry if it’s just a stupid mistake
Thanks for your time!