0

I working on a Unity Game, I converted JavaScript code to C#. I am stuck while assigning the values to an array, I works pretty fine in JavaScript but in C# it gives the following error " error CS1525: Unexpected symbol `,' " As i know there is no error in syntax.

This is JavaScript code and it works fine:

public var primaryPhaseDuration = 20.0;
public var transitionPhaseDuration = 3.0;


function Start () {
stateIntervals =[primaryPhaseDuration,transitionPhaseDuration,transitionPhaseDuration,primaryPhaseDuration,transitionPhaseDuration,transitionPhaseDuration]; 
}

Here is C# code which has the error:

public float primaryPhaseDuration= 20.0f;
public float transitionPhaseDuration= 3.0f
void Start () {
    stateIntervals ={primaryPhaseDuration,transitionPhaseDuration,transitionPhaseDuration,primaryPhaseDuration,transitionPhaseDuration,transitionPhaseDuration}; 
}

I have google it but what i found was the same syntax i am using

3
  • As a quick look you've missed a ; after this line public float transitionPhaseDuration = 3.0f also in C# you should define the type of the stateIntervals as float[] like this:float[] stateIntervals ={ ... Commented Jun 11, 2017 at 11:41
  • hmm czhange 'public float transitionPhaseDuration= 3.0f' to 'public float transitionPhaseDuration= 3.0f;' Commented Jun 11, 2017 at 11:41
  • Thank your for your quick reply, ; was missed during posting the question Commented Jun 11, 2017 at 11:59

1 Answer 1

2

Please try below code:

stateIntervals= new float [] {1.0f, 2.0f, 3.0f};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.