I know this is an older game, but very good at having students see how to put together multiple aspects of a game.
We have worked through everything, except I can’t get the cut scenes to work. Would someone be able to look at this level status script and see if there is some obvious thing I have missed or messed up.
The Game level works by itself, the Start Menu and Game Over menu work on their own.
When I collect the required number of fuel canisters, nothing happens, and I have no errors showing.
// LevelStatus: Master level state machine script.
var exitGateway: GameObject;
var levelGoal: GameObject;
var unlockedSound: AudioClip;
var levelCompleteSound: AudioClip;
var mainCamera: GameObject;
var unlockedCamera: GameObject;
var levelCompletedCamera: GameObject;
var itemsNeeded: int = 20; // This is how many fuel canisters the player must collect.
private var playerLink: GameObject;
function Awake()
{
levelGoal.GetComponent(MeshCollider).isTrigger = false;
playerLink = GameObject.Find(“Player”);
if (!playerLink)
Debug.Log(“Could not get link to Lerpz”);
levelGoal.GetComponent(MeshCollider).isTrigger = false; // make very sure of this!
}
function UnlockLevelExit()
{
mainCamera.GetComponent(AudioListener).enabled = false;
unlockedCamera.SetActive(true);
unlockedCamera.GetComponent(AudioListener).enabled = true;
exitGateway.GetComponent(AudioSource).Stop();
if (unlockedSound)
{
AudioSource.PlayClipAtPoint(unlockedSound,
unlockedCamera.GetComponent(Transform).position, 2.0);
}
yield WaitForSeconds(1);
exitGateway.SetActive(false); // … the fence goes down briefly…
yield WaitForSeconds(0.2); //… pause for a fraction of a second…
exitGateway.SetActive(true); //… now the fence flashes back on again…
yield WaitForSeconds(0.2); //… another brief pause before…
exitGateway.SetActive(false); //… the fence finally goes down forever!
levelGoal.GetComponent(MeshCollider).isTrigger = true;
yield WaitForSeconds(4); // give the player time to see the result.
// swap the cameras back.
unlockedCamera.SetActive(false); // this lets the NearCamera get the screen all to itself.
unlockedCamera.GetComponent(AudioListener).enabled = false;
mainCamera.GetComponent(AudioListener).enabled = true;
}
function LevelCompleted()
{
mainCamera.GetComponent(AudioListener).enabled = false;
levelCompletedCamera.SetActive(true);
levelCompletedCamera.GetComponent(AudioListener).enabled = true;
playerLink.GetComponent(ThirdPersonController).SendMessage(“HidePlayer”);
playerLink.transform.position+=Vector3.up*500.0; // just move him 500 units
if (levelCompleteSound)
{
AudioSource.PlayClipAtPoint(levelCompleteSound, levelGoal.transform.position,
2.0);
}
levelGoal.GetComponent.animation.Play();
yield WaitForSeconds (levelGoal.GetComponent.animation.clip.length);
Application.LoadScene(“GameOver”); //…just show the Game Over sequence.
}
// LevelStatus: Master level state machine script.
var exitGateway: GameObject;
var levelGoal: GameObject;
var unlockedSound: AudioClip;
var levelCompleteSound: AudioClip;
var mainCamera: GameObject;
var unlockedCamera: GameObject;
var levelCompletedCamera: GameObject;
var itemsNeeded: int = 20; // This is how many fuel canisters the player must collect.
private var playerLink: GameObject;
function Awake()
{
levelGoal.GetComponent(MeshCollider).isTrigger = false;
playerLink = GameObject.Find("Player");
if (!playerLink)
Debug.Log("Could not get link to Lerpz");
levelGoal.GetComponent(MeshCollider).isTrigger = false; // make very sure of this!
}
function UnlockLevelExit()
{
mainCamera.GetComponent(AudioListener).enabled = false;
unlockedCamera.SetActive(true);
unlockedCamera.GetComponent(AudioListener).enabled = true;
exitGateway.GetComponent(AudioSource).Stop();
if (unlockedSound)
{
AudioSource.PlayClipAtPoint(unlockedSound,
unlockedCamera.GetComponent(Transform).position, 2.0);
}
yield WaitForSeconds(1);
exitGateway.SetActive(false); // ... the fence goes down briefly...
yield WaitForSeconds(0.2); //... pause for a fraction of a second...
exitGateway.SetActive(true); //... now the fence flashes back on again...
yield WaitForSeconds(0.2); //... another brief pause before...
exitGateway.SetActive(false); //... the fence finally goes down forever!
levelGoal.GetComponent(MeshCollider).isTrigger = true;
yield WaitForSeconds(4); // give the player time to see the result.
// swap the cameras back.
unlockedCamera.SetActive(false); // this lets the NearCamera get the screen all to itself.
unlockedCamera.GetComponent(AudioListener).enabled = false;
mainCamera.GetComponent(AudioListener).enabled = true;
}
function LevelCompleted()
{
mainCamera.GetComponent(AudioListener).enabled = false;
levelCompletedCamera.SetActive(true);
levelCompletedCamera.GetComponent(AudioListener).enabled = true;
playerLink.GetComponent(ThirdPersonController).SendMessage("HidePlayer");
playerLink.transform.position+=Vector3.up*500.0; // just move him 500 units
if (levelCompleteSound)
{
AudioSource.PlayClipAtPoint(levelCompleteSound, levelGoal.transform.position,
2.0);
}
levelGoal.GetComponent.animation.Play();
yield WaitForSeconds (levelGoal.GetComponent.animation.clip.length);
Application.LoadScene("GameOver"); //...just show the Game Over sequence.
}
Some things:
Why is this line of code called twice? levelGoal.GetComponent(MeshCollider).isTrigger=false; It may be important, but calling it twice won’t make a difference. It will either work or fail regardless of the number of times it’s called.
This code doesn’t have any obvious “stand-out” errors. Do you know what code calls these two functions? (UnlockLevelExit, LevelCompleted) These look fine but, of course, won’t be run until they are called from somewhere… You should track down what code calls these functions and check to make sure that they are working correctly.
Thanks so much. I tried hard to solve this, and I was missing those lines in my PlayerStatus script to activate those functions. Good call, and thanks for being patient with me.