Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Unity debug console tell me weird things about a problem in my code

Discussion in 'Scripting' started by Double_vhe, Jan 13, 2021.

  1. Double_vhe

    Double_vhe

    Joined:
    May 3, 2020
    Posts:
    7
    So I was coding a resolution change setting but when i've done a loop for the UI on the screen many errors in the console appeared

    the line is :

    for (int i -0; i < resolutions.Lenght; i++)

    and Unity tell me that the correct line would be :

    for (int i ;-0; i < resolutions.Lenght); i++;})

    I don't understand how to fix it
    Do someone have an idea ?
    (I can show more details of the code or anythings if necessary)
     
  2. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    Can you share Screenshots and code?
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    You definitely have some malformed code before this code that is confusing the compiler.
     
  4. Double_vhe

    Double_vhe

    Joined:
    May 3, 2020
    Posts:
    7
    upload_2021-1-13_19-3-38.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Audio;
    5. using UnityEngine.UI;
    6.  
    7. public class SettingsMenu : MonoBehaviour
    8. {
    9.     public AudioMixer audioMixer;
    10.  
    11.     public Dropdown resolutionDropdown;
    12.  
    13.     Resolution[] resolutions;
    14.  
    15.     public void Start()
    16.     {
    17.         resolutions = Screen.resolutions;
    18.         resolutionDropdown.ClearOptions();
    19.  
    20.         List<string> options = new List<string>();
    21.  
    22.         for (int i -0; i < resolutions.Lenght; i++)
    23.         {
    24.             string options = resolutions[i].width + "x" + resolutions[i].height;
    25.             options.Add(option);
    26.         }
    27.  
    28.         resolutionDropdown.AddOptions(options);
    29.     }
    30.  
    31.   public void SetVolume(float volume)
    32.     {
    33.         audioMixer.SetFloat("volume", volume);
    34.     }
    35.  
    36.     public void SetFullScreen(bool isFullScreen)
    37.     {
    38.         Screen.fullScreen = isFullScreen;
    39.     }
    40. }
    41.  
     
  5. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    You just need to replace - by = in your for loop.
    Like this
    Code (CSharp):
    1.  
    2. for (int i = 0; i < resolutions.Lenght; i++)
    3.  
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    Also
    resolutions.Lenght
    should be
    resolutions.Length
     
    NOT_A_ROBOT1101 and VolodymyrBS like this.
  7. Double_vhe

    Double_vhe

    Joined:
    May 3, 2020
    Posts:
    7
    It work ! Thank you so much I haven't pay enough attention to these things.
     
    NOT_A_ROBOT1101 likes this.