Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question new(this) Error

Discussion in 'Experimental Scripting Previews' started by dnzblg58, Dec 18, 2022.

  1. dnzblg58

    dnzblg58

    Joined:
    Jul 6, 2018
    Posts:
    15
    Hello, why am I getting an error in the code below? Several people said update Unity c#, is that true?
    How do I do that if I need to upgrade the C# version?
    My version of Unity : 2020.3.26f1
    I am using Visual Studio 2019
    error1.jpg error2.jpg
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,882
    Type it out like this:
    new GeneralAdmin(this);

    The new() syntax should work but i can‘t say which c# version introduced that syntactic sugar. You cannot upgrade C# versions in Unity, you can only upgrade Unity to a version which uses a newer C# version.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Yeah that for sure would work in Unity 2021.3, so either use the old syntax or switch to 2021.3 or newer.
     
  4. dnzblg58

    dnzblg58

    Joined:
    Jul 6, 2018
    Posts:
    15