Search Unity

Unable to run most basic script

Discussion in 'Getting Started' started by naughtyknotty, Mar 17, 2018.

  1. naughtyknotty

    naughtyknotty

    Joined:
    Mar 17, 2018
    Posts:
    1
    Hi, I'm new to using Unity and currently using 4.6.9 as recommended by an on line course I'm working through.

    I have installed Unity and have created a basic C# script.

    print ("Hello");

    Like i say, very basic. When I click on play nothing shows in the console window.

    The colour of the screen changes to indicate it is playing, but nothing else happens.

    I'm not looking for advise on coding, just help with verifiying that Unity is working or that my computer is too old/slow to run it.

    Thanks in advance for any suggestions.
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    But why? Recommended for what reason? Frankly I'm sick & tired of professors always teaching outdated things to students.

    Anyway, you use Debug.Log to print things out to the console. "print" is not function that exists.
     
  3. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    @Cucci_A is correct, use Debug.Log.

    You're using a pretty old version of Unity, I'm going to recommend you upgrade to a newer version and also complete several of Unity's tutorials. Unity's tutorials are free and provide an excellent introduction to Unity, game development, and programming. See 'Learn' link above. There are also many other sites to help with learning Unity, try to use the ones that have tutorials closer to the current version of Unity. Many things are new, changed, and removed since version 4.x.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    In addition, what you have above is not a complete script; nor is simply creating a script enough to get Unity to run it. You need to make a MonoBehaviour subclass, and then attach this to a GameObject in the scene. All this is covered by the tutorials mentioned (and I'm sure will be covered in your class, too).
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,190
    It's definitely not valid C#, but it is valid UnityScript.

    If that is the complete script (including any code that was already present when you created it) then that series is not teaching you C# but is instead teaching you UnityScript (which is currently in the process of being stripped out of Unity).

    Using Unity 4 is a bit like downgrading your computer to Windows 95. It's positively ancient now and a great deal of how you use it no longer applies to modern releases. I highly recommend finding a new course or simply using the official tutorials provided by Unity at the link below.

    https://unity3d.com/learn/tutorials

    If you want an actual course though then I highly recommend the following one. It's made for Unity 2017.

    https://www.udemy.com/unitycourse2/

    It's almost always on sale by the way (and in fact if you sign up and not buy anything right away they often send you a coupon code with an insane discount) just in case you miss the currently running sale.
     
    Last edited: Mar 17, 2018
    DocJ and JoeStrout like this.
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Just to clarify .. "print" is a method in MonoBehaviour. I use it all the time.
     
    JoeStrout likes this.
  7. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Ah, my mistake then. I've only ever used Visual Studio.
     
  8. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    hm, yeah.. Try it in a MonoBehaviour in Visual studio. :)
    Code (csharp):
    1. void Start() {
    2.    print("This just calls Debug.Log");
    3. }
    heh
     
  9. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    ...Oh, and I also apparently read your last post wrong. I thought you said MonoDevelop.
    I'm going to take a nap.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Note that "print" only works as an alias for Debug.Log in MonoBehaviour; if you use it in a non-MonoBehaviour class, you get an error. Debug.Log works everywhere. For the sake of consistency it's probably best to forget that "print" exists.

    --Eric
     
    Ryiah likes this.