Well, I’m trying to take the random dungeon generator from → this topic ← and implement it into my game. Thing is, though, the original dungeon generator comes with a lot of other extra features I don’t need, such as a custom character controller, title screen, story-page, random battles, mock-inventory, character stats, etc. And I’m trying extricate the dungeon generator from all those extra features, but I’m having a heck of a time doing it while still keeping the dungeon generator itself intact and functional.
Anyway, in the dungeon generator, there are two colored cubes which represent stairs. The red cube goes down to the next level, while the green cube goes back up to the previous level. With the way the original code is written, there is a dungeon generator object that detects when the player and a colored cube are at the same position, and then preforms the appropriate action (either going down to the next level or up to the previous one). However, in my project I need to use an OnTriggerEnter event to preform the action, since I’m using my own character controller, and not the one that the author provided (the issue is explained in more detail in the topic I linked to at the beginning of this post).
Basically, I just need the DungeonGenerator object to detect when the player collides or comes into contact with the stairs, and then generate the next level.
The DungeonGenerator already has fully functional methods for generating a random level, I just need those functions to be called in a different way than what the author originally programed.
In my own project, I had to create a small little custom script to attach to the red cube to detect a player collision:
clearedLevel.cs:
using UnityEngine;
using System.Collections;
public class clearedLevel : MonoBehaviour
{
public static bool touchedStairsDown;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Down Stairs!");
touchedStairsDown=true;
}
}
}
Anyway, that much of the code seems to work fine, but I can’t figure out how to make the variable touchedStairsDown trigger the two functions that generate the next level. The first function, called GoToNextLevel, is in the DungeonGenerator object:
DungeonGenerator.cs:
public void GoToNextLevel()
{
DeleteDungeonFloor();
CreateDungeonFloor();
DungeonFloorNumber++;
}
And the other function, called SetNewMetaState, is inside another script attached to a game object called the MetaStateManager:
MetaStateManager.cs:
public void SetNewMetaState(MetaState newMetaState)
{
pendingNewMetaState = newMetaState;
}
Basically, I just need those two functions from those two scripts to execute when the variable touchedStairsDown becomes true. Remember, this all needs to be done in C#.