Search Unity

error CS1519: Unexpected symbol `5' in class, struct, or interface member declaration

Discussion in 'Scripting' started by Lapraniteon, May 19, 2018.

  1. Lapraniteon

    Lapraniteon

    Joined:
    May 19, 2018
    Posts:
    3
    Hello,
    I'm new to Unity and coding with C# and I'm getting an error with my code. I'm trying to assign a variable "alphavalue" a value but Unity seems to give me an error about an unexpected symbol in the value. Can someone please help me. I've tried everything I could think of.
    This is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Fade : MonoBehaviour {
    6.  
    7.     public CanvasGroup cg;
    8.     public decimal alphavalue = 0,05;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         cg.alpha = 0;
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update() {
    17.         if (cg.alpha < 1) {
    18.             cg.alpha = cg.alpha + alphavalue;
    19.         }
    20.     }
    21. }
    and here's my error:

    Assets/Fade.cs(8,36): error CS1519: Unexpected symbol `5' in class, struct, or interface member declaration

    Can someone please help me? Thanks.
     
  2. Lapraniteon

    Lapraniteon

    Joined:
    May 19, 2018
    Posts:
    3
    I think it's a problem that I have a decimal number as the value of the variable, but I'm not sure. Can someone confirm?
     
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    You are using the European style for a floating point number. You need to use
    0.05
    , not
    0,05
    . :)
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    the decimal will also require an 'm' suffix, I believe. :)
     
    Doug_B likes this.
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Oops, missed that bit. :confused: