Search Unity

Resolved Coming from python/MATLAB, question about console

Discussion in 'Scripting' started by Latchh, Sep 15, 2020.

  1. Latchh

    Latchh

    Joined:
    Aug 10, 2020
    Posts:
    49
    Is there a way to print out a variable to a console in VS? In the interest of keeping things simple, say I have this:

    Code (CSharp):
    1. public int a = 1;
    2. public int b = 2;
    3. public int c;
    4.  
    5. void Start()
    6.     {
    7.         c = a + b;
    8.         print(c);
    9.     }
    Is there an easier way (ideally within VS) to test whether print(c) returns 3 rather than placing this in a method that unity uses?
     
    Last edited: Sep 15, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    So Unity has its own logging framework and way of invoking code. But that's not the normal C# way of doing things. If you want to just run a quick program in Visual Studio outside of the confines of Unity, start here:

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
    https://docs.microsoft.com/en-us/dotnet/csharp/

    The problem, of course, is that you won't be able to use any of your Unity classes like MonoBehaviours etc.. But if you want to just test a simple function, you can basically just modify the Hello World boilerplate.
     
  3. Latchh

    Latchh

    Joined:
    Aug 10, 2020
    Posts:
    49
    Ah perfect, thanks so much. Does this mean that if I am working in a unity "project", I won't be able to run a .cs file but would rather need to create a new project (like a Console App as in the example you linked)?