Rougelike Map Generation, But OnTriggerEnter not working!

I’m building a game similar to Rouge, where the map changes as you venture, however, the OnTriggerEnter Command isn’t working

My script: `using UnityEngine;
using System.Collections;

public class RougeMapMaking : MonoBehaviour {

public GameObject path1;
public GameObject path2;
public GameObject path3;
public GameObject path4;
public GameObject path5;
public GameObject path6;
public GameObject path7;
public GameObject path8;
public GameObject path9;
public GameObject path10;
public GameObject path11;
public GameObject path12;

int pathNum;

// Use this for initialization
void Start () {
	
}

void OnTriggerEnter(Collider col) {
	if (col.gameObject.tag == "Red") {
					pathNum = Random.Range (0, 11);
					GameObject spawnObj;
					if (pathNum == 0) {
							spawnObj = Instantiate (path1, transform.position, path1.transform.rotation)as GameObject;
					} else if (pathNum == 1) {
							spawnObj = Instantiate (path2, transform.position, path2.transform.rotation)as GameObject;
					} else if (pathNum == 2) {
							spawnObj = Instantiate (path3, transform.position, path3.transform.rotation)as GameObject;
					} else if (pathNum == 3) {
							spawnObj = Instantiate (path4, transform.position, path4.transform.rotation)as GameObject;
					} else if (pathNum == 4) {
							spawnObj = Instantiate (path5, transform.position, path5.transform.rotation)as GameObject;
					} else if (pathNum == 5) {
							spawnObj = Instantiate (path6, transform.position, path6.transform.rotation)as GameObject;
					} else if (pathNum == 6) {
							spawnObj = Instantiate (path7, transform.position, path7.transform.rotation)as GameObject;
					} else if (pathNum == 7) {
							spawnObj = Instantiate (path8, transform.position, path8.transform.rotation)as GameObject;
					} else if (pathNum == 8) {
							spawnObj = Instantiate (path9, transform.position, path9.transform.rotation)as GameObject;
					} else if (pathNum == 9) {
							spawnObj = Instantiate (path10, transform.position, path10.transform.rotation)as GameObject;
					} else if (pathNum == 10) {
							spawnObj = Instantiate (path11, transform.position, path11.transform.rotation)as GameObject;
					} else if (pathNum == 11) {
							spawnObj = Instantiate (path12, transform.position, path12.transform.rotation)as GameObject;
					}
			} else if (gameObject.tag == "PathEntrance")
					Destroy (this.gameObject);
	}

// Update is called once per frame
void Update () {

}

}
`

Hi,

I’m pretty sure you need to use ‘OnCollisionEnter’ instead, as ‘OnTriggerEnter’ requires both gameobjects collided to have a ‘trigger’ property. More information on documentation, click here for information about OnCollisonEnter, and click here for information about OnTriggerEnter.

My information is not 100% correct, so please take a look at the links provided to get fully correct information, as I don’t wish to mislead anyone.

Oh and, this is a little off-topic but you should use a ‘switch’ statement, which will make your code look better(in my opinion).

Here’s an example:

switch(pathNum)
{
    case 1:
         spawnObj = Instantiate (path1, transform.position, path1.transform.rotation)as GameObject;
         break;
    case 2:
         spawnObj = Instantiate (path2, transform.position, path2.transform.rotation)as GameObject;
         break;
    // Etc... keep doing that until you get to your desired number.
}

Oh and, click here for more information on ‘switch’ statements.

Please ask if you need any further assistance.

Best of luck,

SeeSharp.