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 Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Need help with "Hello World" C# script

Discussion in 'Getting Started' started by RichAllen2021, Mar 14, 2022.

  1. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    Above.

    I'm writing the code in Visual Studio for Ubuntu, but it's asking for the C# runtime from .NET to be installed.

    How do I install/run this in Ubuntu? I'm working through the book "Unity in Action - Third Edition"
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please share a screenshot. Are you writing a Unity script or running script in Visual Studio.
     
  3. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    Writing in VS to run in Unity so both.

    Because VS isn't set as the default script editor in Unity 2020, I don't know how to set it up?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You don't run Unity code in Visual Studio, you only edit the code. Please share a screenshot of the error. Do you have Visual Studio installed? Can you run it separately? What do you have for the default editor?
     
  5. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    None, I have VS installed run as a seperate app to Unity in Ubuntu.

    Ubuntu is a supported Linux distro.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Screenshot please that shows the error. And asking again, can you run VS separately? You'll want to set the default editor in Unity under menu Edit/Preferences/External Tools
     
  7. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    I can't show the error image, print screen does not work/I can't get to the clipboard.

    Basically the error is that it says I have to install .NET from the MS website, my Brother has the admin password to install stuff, he is at work.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please get a screenshot. Take it with your phone, and email it to yourself, and post it here. Or get an Ubuntu app (Google it). And again, you are not answering my questions. What do you have for the default editor? Does Visual Studio start up when you launch it separately? Yes/No
     
  9. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    The code I am trying to write is as follows.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class HelloWorld : MonoBehaviour (
    6. void Start {} (
    7.       // do something once
    8.       }
    9.  
    10. void Update { }  (
    11.          //do something every frame
    12.          )
    13. }
    14.  
    15.  
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Screenshot, questions.
     
  11. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    I can't find my phone, stop bugging me.
     
  12. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    Here's a screenshot of VS at the moment with the code I wrote.
    IMG_20220314_164845470_HDR.jpg
     
  13. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    @RichAllen2021 You might consider answering questions when they are asked and we won't need to "bug you" to provide the necessary information to troubleshoot. You are using Visual Code not Visual Studio. And you can ignore that error, you don't run code there, as mentioned. Unity has it's own code compiler. So you can click on Disable message. But the code you shared would not compile in Unity either. You have an incorrect closed paren and closed bracket after Monobehavior. I might suggest that within Unity, you choose Add New Script which will generate a valid C# file for you, with Start() and Update() correctly placed. Click once on Assets, then right click and choose Create/C# Script
     
  14. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
  15. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You have many improper parens and brackets and improper "using" syntax and have the word "generic" only. Please refer to my previous message.
     
    Last edited: Mar 14, 2022
  16. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    Meh, I'm writing the code as written in the book, not my fault they have it wrong.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Interesting! They are publishing incorrect code for you to spot the errors? Otherwise get your camera out again and provide a photo of the code that we can read.
     
  18. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
  19. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    @RichAllen2021 Got it, you have typed it incorrectly in your screenshot above.

    You have "using System.Collectables;Generic;" and should be

    "using System.Collections.Generic;"

    You have "...MonoBehavior ) " and should be

    "...MonoBehavior {"

    You have "Void Start {}) (" and should be

    "void Start() {"

    and a few others. The spelling has to be exact.
     
    Joe-Censored likes this.
  20. RichAllen2021

    RichAllen2021

    Joined:
    Jul 19, 2016
    Posts:
    665
    Thanks man, I'll edit those in the morning, I'm off to sleepy time now, it's quite late :D
     
  21. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You're welcome! That's the default script by the way. You can generate a brand new one as I mentioned before, click once on Assets in Project Explorer, then right click and choose Create/C# Script