Nick Greiner
Nick Greiner

Reputation: 21

Unity "Invalid rank specifier: expected ',' or ']'

So, this error (title) keeps popping up, and I don't know why. Its probably something simple, but I cant see it. Here is the code, I will mark what the error is referring to.

using UnityEngine;
using System.Collections;

public class ScoreCalculator : MonoBehaviour {

    public int[8] finalScore = new int[8]; // it's the first "]" here

    public void IncreaseMyScore (int increaseAmount, int forLevel) {
        finalScore[forLevel] += increaseAmount;
    }

    public void IncreaseByOne (int forLevel) {
        IncreaseMyScore(1, forLevel);
    }

    public void IncreaseByTwo (int forLevel) {
        IncreaseMyScore(2, forLevel);
    }

    public void IncreaseByThree (int forLevel) {
        IncreaseMyScore(3, forLevel);
    }

    public void IncreaseByFour (int forLevel) {
        IncreaseMyScore(4, forLevel);
    }

    public void SaveMyScores () {
        for (int i = 0; i < 8; i++)
            PlayerPrefs.SetFloat("FinalScore"+i,finalScore[i]);
    }
}

That break is not there in the code, just there to show what the error is referring to. Thanks again!

Upvotes: 0

Views: 108

Answers (1)

SLaks
SLaks

Reputation: 887887

Array types do not have sizes. int[] is a type; int[8] doesn't make sense.

Remove the number.

Upvotes: 2

Related Questions