3D Platformer Tutorial spaceShip animation problem

Hello Unity Forums…

I’m close to finishing the 3D Platformer Tutorial and I’m having a problem with the Ship’s animation. It’s triggering correctly, the camera changes to CutSceneCamera2 and I’m hearing the sound effect, but the animation is not executing.

Here’s the error code I’m getting:

MissingComponentException: There is no 'Animation' attached to the "spaceShip" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "spaceShip". Or your script needs to check if the component is attached before using it.

UnityEngine.Animation.Play (PlayMode mode) 
UnityEngine.Animation.Play () 
LevelStatus+LevelCompleted$7+$.MoveNext ()   (at Assets/Scripts/Misc/LevelStatus.js:68)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
ThirdPersonStatus:LevelCompleted() (at Assets/Scripts/Player/ThirdPersonStatus.js:121)
HandleSpaceshipCollision:OnTriggerEnter(Collider) (at Assets/HandleSpaceshipCollision.js:13)

I’m certain the animation is on the spaceShip game object. (See screen grab below) So, I’m wondering where the error is in my scripting. Using the error code, I’ve tried to single out what part of my scripting is at fault, but I’ve triple checked all my code and it’s exactly as the tutorial intended it to be.

Could someone explain to me the error code above so that I might solve this problem?

Can you post the script that is triggering this error?

LevelStatus script

// 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;


// This is where info like the number of items the player must collect in order to complete the level lives.

var itemsNeeded: int = 20;	// This is how many fuel canisters the player must collect.




levelGoal.GetComponent(MeshCollider).isTrigger = false;

function UnlockLevelExit()
{
	mainCamera.GetComponent(AudioListener).enabled = false;
	unlockedCamera.active = 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.active = false;
	yield WaitForSeconds(0.2);
	exitGateway.active = true;
	yield WaitForSeconds(0.2);
	exitGateway.active = false;
	
	levelGoal.GetComponent(MeshCollider).isTrigger = true;
	
	yield WaitForSeconds(4);
	
	unlockedCamera.active = false;
	unlockedCamera.GetComponent(AudioListener).enabled = false;
	mainCamera.GetComponent(AudioListener).enabled = true;
}

 //Called by Unity when the script has loaded.
// We use this function to initialise our link to the Lerpz GameObject.

function LevelCompleted()
{
	mainCamera.GetComponent(AudioListener).enabled=false;
	levelCompletedCamera.active=true;
	levelCompletedCamera.GetComponent(AudioListener).enabled=true;
	
	playerLink.GetComponent(ThirdPersonController).SendMessage("HidePlayer");
	playerLink.transform.position+=Vector3.up*500.0;
	
	if (levelCompleteSound)
	{
		AudioSource.PlayClipAtPoint(levelCompleteSound, levelGoal.transform.position, 2.0);
	}

	levelGoal.animation.Play();
	
	yield WaitForSeconds(levelGoal.animation.clip.length);
	
	Application.LoadLevel("GameOver");
}

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;
	
}	

Awake();

ThirdPersonStatus script

// ThirdPersonStatus: Handles the player's state machine.

// Keeps track of inventory, health, lives, etc.


var health : int = 6;
var maxHealth : int = 6;
var lives = 4;

// sound effects.
var struckSound: AudioClip;
var deathSound: AudioClip;

private var levelStateMachine : LevelStatus;		// link to script that handles the level-complete sequence.

private var remainingItems : int;	// total number to pick up on this level. Grabbed from LevelStatus.


function Awake()
{
	
	levelStateMachine = FindObjectOfType(LevelStatus);
	if (!levelStateMachine)
		Debug.Log("No link to Level Status");
	
	remainingItems = levelStateMachine.itemsNeeded;
}

// Utility function used by HUD script:
function GetRemainingItems() : int
{
	return remainingItems;
}

function ApplyDamage (damage : int)
{
	if (struckSound)
		AudioSource.PlayClipAtPoint(struckSound, transform.position);	// play the 'player was struck' sound.

	health -= damage;
	if (health <= 0)
	{
		SendMessage("Die");
	}
}


function AddLife (powerUp : int)
{
	lives += powerUp;
	health = maxHealth;
}

function AddHealth (powerUp : int)
{
	health += powerUp;
	
	if (health>maxHealth)		// We can only show six segments in our HUD.
	{
		health=maxHealth;	
	}		
}


function FoundItem (numFound: int)
{
	remainingItems-= numFound;

// NOTE: We are deliberately not clamping this value to zero. 
// This allows for levels where the number of pickups is greater than the target number needed. 
// This also lets us speed up the testing process by temporarily reducing the collecatbles needed. 
// Our HUD will clamp to zero for us.
if (remainingItems == 0)
{
	levelStateMachine.UnlockLevelExit();// ...and let our player out of the level
}
}


function FalloutDeath ()
{
	Die();
	return;
}

function Die ()
{
	// play the death sound if available.
	if (deathSound)
	{
		AudioSource.PlayClipAtPoint(deathSound, transform.position);

	}
		
	lives--;
	health = maxHealth;
	
	if(lives < 0)
		Application.LoadLevel("GameOver");	
	
	// If we've reached here, the player still has lives remaining, so respawn.
	respawnPosition = Respawn.currentRespawn.transform.position;
	Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up;	// reset camera too
	// Hide the player briefly to give the death sound time to finish...
	SendMessage("HidePlayer");
	
	// Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
	transform.position = respawnPosition + Vector3.up;

	yield WaitForSeconds(1.6);	// give the sound time to complete. 
	
	// (NOTE: "HidePlayer" also disables the player controls.)

	SendMessage("ShowPlayer");	// Show the player again, ready for...	
	// ... the respawn point to play it's particle effect
	Respawn.currentRespawn.FireEffect ();
}

function LevelCompleted()
{
	levelStateMachine.LevelCompleted();
}

and finally, the HandleSpaceshipCollision script

private var playerLink : ThirdPersonStatus;

function OnTriggerEnter (col:Collider)
{
	playerLink=col.GetComponent(ThirdPersonStatus);
	
	if (!playerLink)// not the player
	{
		return;
	}
	else
	{
		playerLink.LevelCompleted();
	}
}

function Update () {
}

The audio source is attached to the object which has the LevelStatus script, but the object dragged to the levelGoal variable is the one that should have the animation. Are you sure that you have dragged the spaceShip object to the levelGoal variable?

:lol: Hey!!!, that hapen to me too!!!,and to solve that problem you must have the spaceShip in the hierarchy panel and then drag it from here to the levelGoal varible!.
The spaceShip that appear before was from project panel
when you click in the variable the origin it cam from became yelLow

You can whach how it finish now http://www.youtube.com/watch?v=OPOgGKkiZU0

bye!

Thanks guys! It worked!

Thank you for this, I was helping a professor with this tutorial and we had the same problem - levelGoal was referencing the asset, rather than the game object.