Group Group Group Group Group Group Group Group Group Forums

Screencast: Beginning C# Part 5: Arrays

In this episode, you'll learn about arrays and how to use them in C#.

This is a companion discussion topic for the original entry at

Download material .zip is corrupted. Therefore unusable. Cheers

Thanks for the heads up … I’ll take a look.

… also iv’e noticed video editing mistake on PART 10: VARIABLE SCOPE, when you redo the code in void OnDisable() instead of void Start() method. good stuff btw. cheers

Hello to you Brian, I to have noticed the download files don’t work either. When you open them it said a piece is missing and it fails to load??? I am very new to this and my explanation is poor.

For those looking for a workaround, you can just download a future lecture, which includes all previous weeks (note that the following part is actually a review and has no materials, so check out Conditionals)

Heyyyy Brian!
I want to ask u something about the challenge at the end (Making a highscore and then show the avarage of it in the log). Ive been thinking if i was doing it right, and i always got the avarage of the highscore. But i want to hear ur opinion about my code, maybe u can give some advice :smiley: Here is it =

using UnityEngine;

public class Highscore : MonoBehaviour {

public int[] highScore;

void OnDisable()
    int AvarageStart = highScore[0] + highScore[1] + highScore[2] + highScore[3] + highScore[4];

    Debug.Log(AvarageStart / 5);

**I am a beginner to programming (I started for now around a week ago). Im a 13 year old from The Netherlands btw, thats why my English is bad :stuck_out_tongue: **

I hope u will see this message :smile:

1 Like

public int[] highScore;
int AvarageStart=0;
for(int i=0;i<=highScore.Length;i++)

Debug.Log(AvarageStart /highScore.Length );

Hi Brian. First of all thank you so much for this entire guide. I’m finding it incredibly helpful so thank you all for it!

Obviously still learning as this challenge has stumped me completely. Can you help me work out where i’m going wrong and why please?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class averageHighScoreChallenge : MonoBehaviour {

string[] names = { "Player 1: ", "Player 2: ", "Player 3: ", "Player 4: ", "Player 5: " };
string[] playerScore = { "5", "6", "7", "8", "9" };

void OnDisable()
    Debug.Log("These are the highscores for the players of the game: ");
    Debug.Log(names[0] + playerScore[0]);
    Debug.Log(names[1] + playerScore[1]);
    Debug.Log(names[2] + playerScore[2]);
    Debug.Log(names[3] + playerScore[3]);
    Debug.Log(names[4] + playerScore[4]);
void OnEnable()
    Debug.Log("The average score of all the players is: " [0 + 1 + 2 + 3 + 4]);


Thank you in advance

I think the last line of code should be

Debug.Log("The average score of all the players is: " + (playerScore/5) );


Debug.Log("The average score of all the players is: " + ((playerScore[0] + playerScore [1] + playerScore [2] + playerScore [3] + playerScore [4]) / 5 );

Thank you so much! That was it. So close!

weird but the zip file is still corrupted but my code looks like everyone else pretty much so no biggy

Hey Brian, the link is still down, i had downloaded right now and the file was corrupted.

it would be nice if this material had the answer to the challenge as well, this one is quite tricky

Your solution helped me alot, thank you! ^^

i think thats the way to go, of course in the future maybe we are going to see fancier ways to calculate an array than using operators for all variables, but thats a good start :slight_smile:

Thanks for the heads up. I’ve updated the zip file so it’s no longer corrupted.

here is mine:

public int[] highScores;

private void OnDisable()
    int sum = highScores[0] + highScores[1] + highScores[2];
    int average = sum / highScores.Length;
1 Like