Search Unity

How to display text & numbers in console using Debug?

Discussion in 'Scripting' started by Deleted User, Sep 4, 2019.

  1. Deleted User

    Deleted User

    Guest

    I'm still new despite going through a not very comprehensive tutorial. I have checked the example in the unity training website and found https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Touch-position.html. It works well on my device. How do i get it displayed in the console as well ? My code is as follows: As you can see I've tested some basic part and it works properly. The part I've changed to comments is the part that refuses to show anything in the console. Any idea or is this functionality disabled? I'm using Unity 2018.4.7 LTS as it is more stable compared to 2019.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class TouchPositionExample : MonoBehaviour
    6. {
    7.     public Text m_Text;
    8.  
    9.     private void Start()
    10.     {
    11.         Debug.Log("We are in start function");
    12.     }
    13.  
    14.  
    15.     void Update()
    16.     {
    17.  
    18.         Debug.Log("We are in update function");
    19.  
    20.         if (Input.touchCount > 0)
    21.         {
    22.             Touch touch = Input.GetTouch(0);
    23.  
    24.             //Update the Text on the screen depending on current position of the touch each frame
    25.             m_Text.text = "Touch Position : " + touch.position;
    26.  
    27.             Debug.Log("Touch Position : " + touch.position.ToString());
    28.             /*
    29.             Debug.Log("Touch Position :  + touch.position");
    30.             Debug.Log(touch.position);
    31.             Debug.Log(m_Text.text);
    32.             Debug.Log("m_Text.text");
    33.             */
    34.         }
    35.     }
    36. }
     
  2. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60
    Input.touchCount
    won't work in editor use
    Input.GetMouseButtonDown(0)
     
  3. Neriad

    Neriad

    Joined:
    Feb 12, 2016
    Posts:
    125
  4. Deleted User

    Deleted User

    Guest

    Do you mean editor or in player mode? Please clarify. I used player mode, opened the console and nothing happened. I know about mousebutton down - i already used it and it works.
     
  5. Deleted User

    Deleted User

    Guest

    Last edited by a moderator: Sep 4, 2019
  6. Vinayak-VC

    Vinayak-VC

    Joined:
    Apr 16, 2019
    Posts:
    60
    by Editor means "Unity Editor". Unity Editor won't give callbacks when using
    Input.touchCount
    .
    But if you use this asset suggested by our friend @Neriad, you can check the log inputs in your android or IOS app.

    If you are developing Android application then make it "Developer Build" and connect it with editor's Console and you can have all the debugs in unity editor,

    I have attached Screenshots about Developer build and also console window.

    If you know how to attach visual studio debugger to you apk then you can check everything line by line by putting a breakpoint.
     

    Attached Files:

    MadeFromPolygons likes this.
  7. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Or stop doing mobile tutorials before learning how to do standard unity development first, as has been said so many times by everyone in the other thread you have made recently about said tutorials.

    I really doubt youve learnt enough in that short time between then and now to be at the level to jump onto android or iOS without causing yourself more headaches than its worth. Im not saying its not possible, just that you will take way longer to learn the same theory because your adding in additional things when you should be focusing on the basics.
     
  8. Deleted User

    Deleted User

    Guest

    I don't want to start an argument with you but when did they say to learn standalone first? This was not stated.
    What makes you think that I'm not unity tutorials? I'm testing them on my device. I will ask if it's the results just don't work out. I will check standalone tutorials but the instructor did mention C# is different from unity c#. That's why I'm here. Are you saying the instructor is wrong? If you're serious, I will let the instructor know.
     
  9. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    We said to start with standard unity and not mobile. Standard unity is the default platform - standalone. It was said in one of the many threads you posted, possibly one of the locked ones that was going in circles before being locked by admins.
    I am not sure what you are talking about, you seem to be thinking standalone somehow means something that it doesnt? Standalone is the default target build platform when you start any unity project.

    c# is c#, unity api is unity api, and any instructor saying c# itself is different in unity isnt explaining it right at all. Some c# concepts are used differently in unity, but c# is still very much c#.
     
  10. Deleted User

    Deleted User

    Guest

    ok i will note this. Well i don't know why the instructor gave that information.
     
    MadeFromPolygons likes this.
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    To be fair a lot of people get confused and describe unity as having "different" c#, so it can get confusing even if following instructors.

    Basically its all c# but some concepts of c# are used weirdly. I dont have time to write them all for you but here are some off top of my head to help you a bit:

    1. Public, private, access modifiers - in normal c# public is used mostly to determine how another class can access the field. In unity a lot of people use it to just make it visible in the inspector. But a tip: dont do that! Instead use https://docs.unity3d.com/ScriptReference/SerializeField.html with a private variable and you can have it visible in inspector without using public unncessarily

    2. Monobehaviours - unity is mostly built using monobehaviours as the main tool for development ,and they have their own strange lifecycle and nuances https://docs.unity3d.com/uploads/Main/monobehaviour_flowchart.svg

    3. A lot of people start using unity before learning c# and assume the way they use it or learnt to use it is correct, and often is not! Theres not much you can do about this as often learning c# first is not a fun task, and not necessary. Just have to be careful to double check anything you learn with another source to make sure it is a fact and not an opinion, as theres a lot of that going around with some tutorials out there!


    Overall try not to worry too much about the c# vs unity side of things, as long as you can get done what you need to it doesnt really matter how you understand the low-level programming side of things :)
     
    ValentineCat likes this.
  12. Deleted User

    Deleted User

    Guest

    You have to excuse me for all the problems I caused in all the earlier threads because I was misled by the instructor. I'm not sure how this kind of mistake can be made. The person does have a degree in IT, so that's really bad.

    Anyway bear in mind that I've already been exposed to modern day languages like vb.net, java & android studio so it probably won't be long before I return. Perhaps in a month or a bit longer, I'll probably be back with more questions. Just be ready by then. I'm not worried about the differences to unity c#. What i'm wondering is how a person with degree qualifications can say such things. Yes thank you for the notes. I appreciate it.
     
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I can only imagine one root cause for this misconception: extreme laziness. I can imagine someone might look up some Unity sample code for some function, seeing special Unity classes being used there, and jumping to the conclusion that it's therefore not standard C#. For example, in standard C#, you'll have a "public static void Main()" sort of method in your class which kicks off all your other code; Unity doesn't do that (at least, not in any part of the code visible to the Unity dev). Most C# classes are initialized with constructors, while Unity classes are initialized in Awake() and Start(). If looking very casually at these examples I can imagine coming off with the impression that it's not normal C# - even if looking any deeper at them will reveal things like the classes being inherited from MonoBehaviour, and that being responsible for most of the apparent differences. Hence, laziness.

    It may be exacerbated by some poor coding-language decisions Unity made in the past. Unity used to use both C# and JavaScript.... but the "JavaScript" wasn't JavaScript - it was a unique, custom-made language that took the Boo language and dressed it up to vaguely resemble JavaScript. But you could never, for example, copy any web Javascript sample code and pasting it into Unity, it just plain wouldn't compile, even for really simple algorithms. This didn't stop them from advertising that Unity supported JavaScript in their marketing material for over a decade, which was essentially a marketing lie to try and trick web developers into using Unity, thinking the transition would be easier than it actually is. It's not too big of a stretch on your instructor's part to assume the same of Unity's C#, and is in a roundabout way Unity's own chickens coming home to roost (if you call something "JavaScript" for a decade without it ever having been JavaScript, can't be too surprised if people don't trust that the thing you call "C#" isn't really C#).

    Of course, that mindset shouldn't survive any actual encounter with code that the professor looks at with any scrutiny, so it still requires a fair bit of laziness to hold on to that assumption.
     
  14. Deleted User

    Deleted User

    Guest

    I see this at the bottom of your reply. Is this computer generated by Unity or you inserted this?

    I don't know why you wrote all those comments. The instructor is too busy creating new courses - lots of courses in udemy and won't bother coming here to check what we said.
     
  15. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    They wrote their post to help you, not the instructor.
     
  16. Deleted User

    Deleted User

    Guest

    I have one last same get touch tutorial in my udemy course that uses the same https://assetstore.unity.com/packages/tools/integration/log-viewer-12047 link but the problem is this only worked once. Is there another link that has similar functions? When i tried it the second time, it just won't work. Any idea why the reporter object refuses to work the second time? I have inserted a question in github but i'm not sure if anyone can solve it.

    Note: As what @GameDevCouple_I said, I'm on the Ruby adventure course now and it's quite easy.