- put the project window into a single coloum layout this way was can drag sound onto the assets easily
- select the explosion astorid pre fab and drag the explosion sound onto it in the inspector and select play on awake
- do this for all explosions and then add the Shooting sounds onto the play game object in the hierarchy ( on the player game object deselect play on awake )
- to get the shot sounds to play go into the game controller script and in the void update write audio.Play ();
- then add background music to the game controller object and select play on awake and loop
- then turn the volumes down to what sounds correct
- create a new gui text and call it score text in the text box write score text and move it to the top left corner
- open the game controller script and wrtie public GUIText scoreText private int score;
void UpdateScore () { scoreText.text = "Score: " + score; }
void Start ()
{
score = 0;
UpdateScore ();
StartCoroutine (SpawnWaves ());
}
public void AddScore (int newScoreValue)
{
score += newScoreValue;
UpdateScore ();
}
the script should now look like this
- open the destroy by contact script and write
public int scoreValue;
private GameController gameController;
void Start ()
{
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <GameController>();
}
if (gameController == null)
{
Debug.Log ("Cannot find 'GameController' script");
}
}
the script will now look like this
change the score value on the asteroid that contains the destroy by contact script
and refference the score text object made on the game controller object
No comments:
Post a Comment