Help i am new!

Note: I don’t know that i am posting it in right place or not as i am new but i have a wired problem in scripting and i want to fix it as soon as possible.
Script:

#pragma strict

var maxFallDistance = -10;

function Update ()
{
if(transform.position.y <= maxFallDistance)
{
RestartLevel ();
}
}

function RestartLevel ()
{
audio.Play();
yield WaitForSeconds (audio.clip.length);
Application.LoadLevel(“Level 1”);
}

Errors:

  1. Assets/Scripts/BallHealth.js(15,5): BCE0144: ‘UnityEngine.Component.audio’ is obsolete. Property audio has been deprecated. Use GetComponent() instead. (UnityUpgradable)
  2. Assets/Scripts/BallHealth.js(15,11): BCE0019: ‘Play’ is not a member of ‘UnityEngine.Component’.
  3. Assets/Scripts/BallHealth.js(16,27): BCE0144: ‘UnityEngine.Component.audio’ is obsolete. Property audio has been deprecated. Use GetComponent() instead. (UnityUpgradable)
  4. Assets/Scripts/BallHealth.js(16,33): BCE0019: ‘clip’ is not a member of ‘UnityEngine.Component’.

Please anyone help!

the errors say it all. Instead of audio, you need to use GetComponent(). Store it in a AudioSource variable so you dont need to keep calling getcomponent.

replace audio.Play();
that with
this GetComponent() i

They’ve already helped with your question. Allow me to help with your etiquette:

  1. Yes, this is the right place to post this sort of question.

  2. When posting code, surround it with code tags. This gives us line numbers and nicely formats it, and makes it much easier for us to help you solve your problem.

  3. Thanks for posting the full text of the error message, you wouldn’t believe how often new posters don’t do that.

  4. Use a more descriptive title.

2 Likes

Thanks All :smile: