Search Unity

using System.Diagnostics; C# Code auto-fill

Discussion in 'Scripting' started by ZyderNarfall, Jul 13, 2020.

  1. ZyderNarfall

    ZyderNarfall

    Joined:
    Jun 11, 2020
    Posts:
    8
    So Unity autoGenerates this line of Code.
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Learning : MonoBehaviour
    7. {
    8.    // Start is called before the first frame update
    9.     void Start()
    10.       {
    11.      
    12.       }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.       {
    17.      
    18.       }
    19. }
    20.  
    When I add | int x = 3;
    then in the void start method i add Debug.
    Visual studio auto Generates this line of code using System.Diagnostics;
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Diagnostics;
    5. using UnityEngine;
    6.  
    7. public class Learning : MonoBehaviour
    8. {
    9.     int x = 4;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.       {
    13.         Debug.Log (x);
    14.       }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.       {
    19.      
    20.       }
    21. }
    22.  
    and I get this error = Assets\Learning.cs(12,9): error CS0104: 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'System.Diagnostics.Debug'

    My question here is how to I keep Visual Studio from adding | using System.Diagnostics;
    into my code. When I delete that line of code I can run my scene and my Console will print out 4.
     
    Last edited: Jul 14, 2020
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Probably Intellisense not working correctly. Try:
     
    MichelBoom likes this.
  3. ZyderNarfall

    ZyderNarfall

    Joined:
    Jun 11, 2020
    Posts:
    8
    So unfortunately that is not what I am talking about.
    When I type in
    Debug.Log
    using System.Diagnostics;
    will auto fill in between
    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    3. using System.Diagnostics; <This is being auto-filled in]
    4. using UnityEngine;
    5.  So if I try to put in
    6. int x = 4;
    7.  
    8. void Start ()
    9. {
    10. Debug.Log (x);
    11. }
    12.  
    it will auto fill in using System.Diagnostics;
    which will pull up the previous error.
    While if I delete the using System.Diagnostics; or comment it out

    Code (csharp):
    1.  
    2. using System.Collections.Generic;
    3. //using System.Diagnostics; <or delete]
    4. using UnityEngine;
    5.  
    6. int x = 4;
    7.  
    8. void Start ()
    9. {
    10. Debug.Log (x);
    11. }
    12.  
    and run the scene it will put on my console 4
    I just don't want the using System.Diagnostics; to auto fill in every time I type in Debug.Log
     
    Last edited: Jul 14, 2020
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980

    Please use codetags, it makes it really hard to read your posts otherwise .
     
  5. ZyderNarfall

    ZyderNarfall

    Joined:
    Jun 11, 2020
    Posts:
    8
    Code tags?
    I’m sorry but I’m new to all of this.
    Basically typing Debug.Log auto fills in using System.Diagnostics;
    I just want to disable the auto fill in of using System.Diagnostics;
     
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    https://forum.unity.com/threads/using-code-tags-properly.143875/

    There you go mate :) No worries I know its all confusing, I was talking about your post here not the code you have.

    Once you format your code it will be easier for everyone to read it and you will get an answer quickly :) I am on a phone on a train otherwise I would read it as it is but currently its really hard to read on my mobile phone in its format with the migraine I have currently, but format it properly and I will get back to you. If you cant work out the code tag thing, I will take a look at this in its current form when I get home and get back to you later if no one else has sorted it for you already :)
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    It's good advice, but this isn't a question that has to do with the actual scripting (just the Visual Studio application) so it's not really critical for this post.
    I know the problem isn't precisely what is described in the video, but I think the underlying cause is the same (that Visual Studio isn't receiving information about Unity classes), and if so the solution should be the same. Did you try the steps shown in the video?
     
    ZyderNarfall likes this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    I know, I was mostly asking because I am on mobile on a train and my phone screen is crappy + I have a migraine, so I was struggling to read it.
     
  9. ZyderNarfall

    ZyderNarfall

    Joined:
    Jun 11, 2020
    Posts:
    8
    Ok, so I did try and it does seem to be the cause of what was going on. Thank you for helping.
    Now when I type in Debug.
    The using System.Diagnostics; does not show up.
     
    StarManta likes this.
  10. ZyderNarfall

    ZyderNarfall

    Joined:
    Jun 11, 2020
    Posts:
    8
    I went ahead and changed it. I'm sorry about your migraine, hope you feeling better though.
    Thank you for showing me how to put the (code) thing into my post so I know how to do that now too.
     
    Last edited: Jul 24, 2020