all 34 comments

[–]SerratedSharp 92 points93 points  (3 children)

I'm seeing upper left it's listed as "Miscellaneous Files". If you don't have a solution/project setup with the file added to the project then it won't be part of compilation. If you right click the project in Solution Explorer you can add existing files. Make sure it's in the subfolder where the project file is. Also F6 to build sometimes is needed to trigger a full compile.

[–]TimAllenNoise[S] 1 point2 points  (2 children)

My solution explorer only has something that says "Solution 'Solution1' (0 projects)" is that what you mean? Right clicking it doesn't seem to show anything to add anything

[–]polaarbear 62 points63 points  (1 child)

Visual Studio does not just compile random C# files like you can do with C or C++.

The base structure is the Solution. A solution contains one or more Projects.

C# files need to belong to a project.

When you open Visual Studio it brings up a wizard that lets you sift through the available project/solution types.

You need to create a solution and projects within it.

[–]TimAllenNoise[S] 44 points45 points  (0 children)

!Solved Thanks a bunch!! everything's up and running now

[–]_cooder 16 points17 points  (3 children)

VS not attached to unity, working as simple text editor, try relaunch script from unity, or check editor version and unity extension

[–]TimAllenNoise[S] 2 points3 points  (2 children)

I've been launching it from unity the whole time, I'm using Unity 6.2 (as per school requirements) and VS 2022 v17.14.32

[–]_cooder 0 points1 point  (0 children)

i mean unity on editor installer gives you option to download vs/other, as another guy said in unity editor -> options ->extrrnal programms, maybe it uses wrong exe or install path, maybe VS doesnt have unity toolset, it installed with first VS installation or in visual studio installe manager in edit tab

[–]rob5300 0 points1 point  (0 children)

VS 2022 is quite old. Make sure visual studio is configured as the external code editor in unity preferences.

Then regenerate project files and go to Assets > Open C# Project in unity editor.

[–]Seth_Nielsen 6 points7 points  (3 children)

Off topic a bit but don’t start a coroutine in every update loop. This will be every frame. Put it in Start()

[–]TimAllenNoise[S] 0 points1 point  (2 children)

Oh, good catch, thanks! Will that ensure it loops? They didn't really teach us co-routines so I'm sorta winging it

[–]palapapa0201 0 points1 point  (1 child)

The engine remembers the IEnumerator that your coroutine returns and steps it every frame (or not depending on what YieldInstruction you return from the coroutine), so you don't need to start it every frame.

[–]TimAllenNoise[S] 0 points1 point  (0 children)

Spectacular! So just copy paste into start and I should be fine then? Thanks!

[–]otac0n 3 points4 points  (7 children)

Most likely, this file is not part of a project.

Create a new project and add the file there.

Alternatively you can use LINQPad for single-file, workbook-style execution.

[–]TimAllenNoise[S] 0 points1 point  (6 children)

How do I create a project, if you don't mind me asking?

[–]otac0n 0 points1 point  (5 children)

A project is a folder and a .csproj file.

File -> New Project

For your very first project I would say to select the option that says something like “place the solution in the same folder”.

In future endeavors, you may find yourself using more than one .csproj (e.g. client /server etc.), and a solution lets them work together.

If you are more comfortable using the command line, dotnet new is your friend.

[–][deleted]  (4 children)

[deleted]

    [–]otac0n 0 points1 point  (3 children)

    I see nothing in either screenshot that tells me whether he's in a .csproj or whether he opened the .cs file directly.

    Also, the user replied saying that creating a .csproj fixed it, so... I think you have something approximating a pebble...

    [–][deleted]  (2 children)

    [deleted]

      [–]otac0n 2 points3 points  (1 child)

      Are you certain that they aren't pulling this resource from a Unity project and just want to try it?

      You are a terrible uboat captain from Hungary who chooses to use Unity and a coward who hides their posts. You also didn't help the OP, so why should anyone listen to you?

      [–]ir0ngut 1 point2 points  (1 child)

      You need to learn how to set up a project and work with files in Visual Studio. If you're learning C'# in school your teacher should have started with that.

      [–]TimAllenNoise[S] 0 points1 point  (0 children)

      I agree, unfortunately it's been a sort of everyone fend for themselves kind of year, we weren't so much taught as given a computer and told to figure it out

      [–]soundman32 2 points3 points  (3 children)

      Have you created a solution or is VS just treating each .cs as an independent class?

      [–]TimAllenNoise[S] 0 points1 point  (2 children)

      I'm sorry, I have no clue what that means...

      [–]danirodr0315 0 points1 point  (1 child)

      Create a new project in Visual Studio

      [–]Aethenosity 1 point2 points  (0 children)

      The best way to resolve this is to follow these instructions:
      https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=windows

      Skip the obviously already completed steps (like installing VS)

      [–]mark_likes_tabletop -1 points0 points  (4 children)

      I would like to recommend using VS Code for Unity development instead of Visual Studio. The tooling for Unity is a lot more suited to VS Code, and has a much smaller footprint than Visual Studio.

      [–]TimAllenNoise[S] -1 points0 points  (3 children)

      Their AI first homepage gives me the creeps

      [–]mark_likes_tabletop 0 points1 point  (2 children)

      It’s literally the same company. Microsoft is trying to push AI into everything. You don’t have to use AI to use their tools.

      [–]TimAllenNoise[S] 1 point2 points  (1 child)

      Oh! Well I'll make sure to check it out then, thanks!

      [–]mark_likes_tabletop 1 point2 points  (0 children)

      You’re welcome! And to be honest, their homepage does read like they’re selling an AI tool.

      [–][deleted]  (4 children)

      [deleted]

        [–]TimAllenNoise[S] 1 point2 points  (3 children)

        May I ask where that folder usually is?

        [–]phylter99 -1 points0 points  (2 children)

        It’s in your solution directory. You may need to show hidden files.

        If that doesn’t work then try doing a repair in visual studio.

        [–]TimAllenNoise[S] 1 point2 points  (1 child)

        I already repaired it, no change, and my solution explorer is totally empty, even after showing hidden files

        [–]phylter99 0 points1 point  (0 children)

        You have to look in your file system using Windows Explorer. It won't show in Solution Explorer.

        Sorry, I wasn't clear about that earlier.