Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question error CS0200 how to fix it?

Discussion in 'Scripting' started by khalilm376447, Mar 26, 2023.

  1. khalilm376447

    khalilm376447

    Joined:
    Mar 2, 2023
    Posts:
    18
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using TMPro;
    public class VideoandAudio : MonoBehaviour
    {
    public Toggle fulltog, vtog;
    public List<ResItem> resolutions = new List<ResItem>();
    private int selectedResolution;
    public TMP_Text resolutionLabel;
    // Start is called before the first frame update
    void Start()
    {
    fulltog.isOn = Screen.fullScreen;
    if (QualitySettings.vSyncCount == 0)
    {
    vtog.isOn = false;
    } else
    {
    vtog.isOn = true;
    }
    bool foundRes = false;
    for(int i = 0; i < resolutions.Count; i++)
    {
    if (Screen.width = resolutions.horizontal + Screen.height == resolutions.vertical) ;
    {
    foundRes = true;
    selectedResolution = i;
    UpdateResLabel();
    }
    }
    }
    // Update is called once per frame
    void Update()
    {

    }
    public void resleft()
    {
    selectedResolution--;
    if(selectedResolution < 0)
    {
    selectedResolution = 0;
    }
    UpdateResLabel();
    }
    public void resright()
    {
    selectedResolution++;
    if (selectedResolution > resolutions.Count - 1)
    {
    selectedResolution = resolutions.Count - 1;
    }
    UpdateResLabel();
    }
    public void UpdateResLabel()
    {
    resolutionLabel.text = resolutions[selectedResolution].horizontal.ToString() + " x " + resolutions[selectedResolution].vertical.ToString();
    }
    public void ApplyChanges()
    {
    Screen.fullScreen = fulltog.isOn;
    if (vtog.isOn)
    {
    QualitySettings.vSyncCount = 1;
    }
    else
    {
    QualitySettings.vSyncCount = 0;
    }
    Screen.SetResolution(resolutions[selectedResolution].horizontal, resolutions[selectedResolution].vertical, fulltog.isOn);
    }
    }
    [System.Serializable]
    public class ResItem
    {
    public int horizontal, vertical;
    }
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    18,898
    The code seems to have a typo error in line 32. The conditional statement should be using "==" for comparison, not "=" which is used for assignment. So, the correct code would be:
    Code (csharp):
    1. if (Screen.width == resolutions[i].horizontal && Screen.height == resolutions[i].vertical)
    2. {
    3.     foundRes = true;
    4.     selectedResolution = i;
    5.     UpdateResLabel();
    6. }
    Also, there is a semicolon after the conditional statement, which would make the following block always execute regardless of the condition. This semicolon should be removed.
     
  3. khalilm376447

    khalilm376447

    Joined:
    Mar 2, 2023
    Posts:
    18
    thank you very much
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    9,404
    I know you've been asked this previously so, in the future, please use code-tags when posting code and not plain text. At least then there's line numbers to refer to.

    Also, don't post the error codes, post the error description and line/column numbers i.e. the full error you are provided. The error code alone isn't useful.

    Thanks.
     
    Bunny83 likes this.