Okay,
So I find the FPS Player scripts a bit hard to follow regarding loading levels.I like the way the new tutorial fades to white on player die, But Im dammed if i can get it to load the right level. Heres the new loading bits…
Which obviously loads the current level. Id be keen for this to work:LevelLoadFade.FadeAndLoadLevel(Application.LoadLevel("GameOver"), Color.white, 2.0);
But thats not gonna work. I couldnt find any references for any of this:LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel
Yo any help here would be grand. Currently Unity crashes when in game using my code…And Ive bug reported it…Thanks guys
EDIT
Ummm, okay, got it now, found the script in misc scripts of newFPS Tut
No worries
Yeah I talk my problems out loud in real life too, and then I generally find the answers.
I tell a lie. I got it to compile, but no it doesnt work. fades then crashes completely. Bummer ay?
Luckily theres access to the editmodescene file to catch up on unsaved work, as repeated crashes can be devastating. do a search for a thread called autosave if you’re not sure what I mean.
What happens to yours? complete application shutdown? Same thing with standalone builds. I think Joe wrote the code. For now we could bug him with a stream of bug reports…?
Heres one that fades, ignores the yield statment and crashes Unity completely. My level is in build settings.
function OnTriggerEnter( Col : Collider)
{ yield WaitForSeconds(36);
LevelLoadFade.FadeAndLoadLevel("GameOver", Color.black, 30.0);
}
And heres my fps playerscript, which also fades, and completely crashes Unity.
var maximumHitPoints = 100.0;
var hitPoints = 100.0;
var bulletGUI : GUIText;
var rocketGUI : GUITexture;
var healthGUI : GUITexture;
var walkSounds : AudioClip[];
var painLittle : AudioClip;
var painBig : AudioClip;
var die : AudioClip;
var audioStepLength = 0.3;
private var machineGun : MachineGun;
private var rocketLauncher : RocketLauncher;
private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;
function Start ()
{
machineGun = GetComponentInChildren(MachineGun);
rocketLauncher = GetComponentInChildren(RocketLauncher);
PlayStepSounds();
healthGUIWidth = healthGUI.pixelInset.width;
}
function ApplyDamage (damage : float) {
if (hitPoints < 0.0)
return;
// Apply damage
hitPoints -= damage;
// Play pain sound when getting hit - but don't play so often
if (Time.time > gotHitTimer painBig painLittle)
{
// Play a big pain sound
if (hitPoints < maximumHitPoints * 0.2 || damage > 20)
{
audio.PlayOneShot(painBig, 1.0 / audio.volume);
gotHitTimer = Time.time + Random.Range(painBig.length * 2, painBig.length * 3);
}
// Play a small pain sound
else
{
audio.PlayOneShot(painLittle, 1.0 / audio.volume);
gotHitTimer = Time.time + Random.Range(painLittle.length * 2, painLittle.length * 3);
}
}
// Are we dead?
if (hitPoints < 0.0)
Die();
}
function Die ()
{
if (die)
AudioSource.PlayClipAtPoint(die, transform.position);
// Disable all script behaviours (Essentially deactivating player control)
var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
for (var b in coms)
{
var p : MonoBehaviour = b as MonoBehaviour;
if (p)
p.enabled = false;
}
LevelLoadFade.FadeAndLoadLevel("GameOver", Color.red, 2.0);
}
function LateUpdate ()
{
// Update gui every frame
// We do this in late update to make sure machine guns etc. were already executed
UpdateGUI();
}
function PlayStepSounds ()
{
var controller : CharacterController = GetComponent(CharacterController);
while (true)
{
if (controller.isGrounded controller.velocity.magnitude > 0.3)
{
audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
audio.Play();
yield WaitForSeconds(audioStepLength);
}
else
{
yield;
}
}
}
function UpdateGUI ()
{
// Update health gui
// The health gui is rendered using a overlay texture which is scaled down based on health
// - Calculate fraction of how much health we have left (0...1)
var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);
// - Adjust maximum pixel inset based on it
healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;
// Update machine gun gui
// Machine gun gui is simply drawn with a bullet counter text
if (machineGun)
{
bulletGUI.text = machineGun.GetBulletsLeft().ToString();
}
// Update rocket gui
// We use a quicktime movie with 20 frames to display how many are left
// The alpha of the movie changes every frame thus rockets get masked out when changing the frame.
if (rocketLauncher)
{
var rocketTexture : Texture2D = rocketGUI.texture;
rocketTexture.frame = rocketLauncher.ammoCount;
}
}
Obviously I must be doing two things wrong, one for each script I guess,
Thanks
AC
Nope. It still claims it’s an “unknown identifier” in the console.
Edit: I opened the FPS tutorial and noticed the script was placed in the “misc scripts” folder, so I tried placing the script in my “scripts”-folder and then everything was just peach cobbler. I don’t know if this helps you, though.
So am I to edit the LevelLoadFade Script?
Or does the fps Player script reference it and it does not require editing?
I could see where to mod that one perhaps but not really understand. I need to reference to a “game over” level and a “mission accomplished” level as results of occurances in the game…
Thanks Joachim
AC