Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Using code tags properly

Discussion in 'Editor & General Support' started by Adam-Buckner, May 3, 2012.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    If you see someone who needs to know about code tags, please link them to this post:

    Please use code tags when posting code.

    You can "tag" your code by typing Screenshot 2015-03-16 10.33.58.png around your code.

    There is no overt "Code" tag button which automatically tags a selection as code.

    That being said, however, we can Insert code directly into the post using "Insert/Code":
    Screenshot 2014-06-04 12.36.27.png

    This will bring up an "Insert" window were we can paste our code and choose our language:
    Screenshot 2014-06-04 12.39.53.png

    This will insert this code with Forum Markup that looks like this:
    Screenshot 2014-06-04 12.43.25.png
    Note: that when manually inserting code, we can choose the language by using "=CSharp"

    This is the final code in the post:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Explode : MonoBehaviour {
    5.  
    6.     public GameObject explosion;
    7.     public ParticleSystem[] effects;
    8.  
    9.     void OnCollisionEnter2D (Collision2D collision) {
    10.         if (collision.gameObject.tag == "Hat") {
    11.             Instantiate (explosion, transform.position, transform.rotation);
    12.             foreach (var effect in effects) {
    13.                 effect.transform.parent = null;
    14.                 effect.Stop ();
    15.                 Destroy (effect.gameObject, 1.0f);
    16.             }
    17.             Destroy (gameObject);
    18.         }
    19.     }
    20. }
    21.  
    Note: the code is linked to the documentation with hyperlinks, so if you need to find out more about any piece of pasted code, follow these links to the documentation.

    Hope this helps!

    -

    If you don't use code tags, the code can be difficult to read:

    using UnityEngine;
    using System.Collections;

    public class Explode : MonoBehaviour {

    public GameObject explosion;
    public ParticleSystem[] effects;

    void OnCollisionEnter2D (Collision2D collision) {
    if (collision.gameObject.tag == "Hat") {
    Instantiate (explosion, transform.position, transform.rotation);
    foreach (var effect in effects) {
    effect.transform.parent = null;
    effect.Stop ();
    Destroy (effect.gameObject, 1.0f);
    }
    Destroy (gameObject);
    }
    }
    }
     
    Last edited: Apr 28, 2015
    PersianKiller and MrEsquire like this.
  2. MellowNinja

    MellowNinja

    Joined:
    Mar 26, 2012
    Posts:
    345
    aha this is great :) there are a lot of people on this forum who dont use the
    Code (csharp):
    1.  so the script is easier read
     
  3. pivotraze

    pivotraze

    Joined:
    Feb 4, 2012
    Posts:
    594
    Shouldn't it be "Confusing" and not "Confused?" :) But yeah, I completely agree with this, I get so mad when people don't use code tags xD
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    Interesting... I would have said "The code is confusing" or "The code looks confused". I guess I'm not sure what the actual proper grammar is!
     
  5. OmniverseProduct

    OmniverseProduct

    Joined:
    Feb 26, 2012
    Posts:
    1,569
    I would actually put "The code looks confusing"
     
    Merman likes this.
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    Either way, this is a good page to share if people need to know about code tags.
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    24,173
    Using the code tags will ensure experienced programmers give you the time of day. Otherwise, they usually won't bother as time is precious for them :)
     
  8. bandingyue

    bandingyue

    Joined:
    Nov 25, 2011
    Posts:
    132
    Code (csharp):
    1.  
    2.  
    3. void Start(){
    4.    Debug.Log("Thank you");
    5. }
    6.  
    7.  
     
  9. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    487
    how do you copy/paste without the line number being in there?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,917
    Don't use Internet Explorer. (Although there are issues with Webkit-based browsers having a blank line between each line.)

    --Eric
     
  11. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    487
    I tried Firefox and safari. I always have to delete the line numbers.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    Cherub: I find that it depends upon where you paste the code.

    If I paste to copied code into MonoDevelop or into a forum post, I get the added lines, but no line numbers, but if I paste the code into Mail or TextEdit, I get the line numbers, but no added lines.

    Go figure.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,917
    Surely not. ;) That definitely doesn't happen here...I don't get line numbers in TextEdit, just always the extra blank lines.

    Edit: hang on, I actually do get the line numbers in Mail though.

    --Eric
     
  14. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    487
    i get the line numbers the same way in: text edit, unitron, xcode, gmail.

    C
     
  15. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,549
    I want to use Internet Explorer and be able to copy without line numbers at the same time.
     
  16. Android324

    Android324

    Joined:
    Jun 20, 2012
    Posts:
    7
    Code (csharp):
    1. public void GotThat()
    2. {
    3.    print ("Sir, Yes,Sir !!!");
    4. }
     
  17. scooter339

    scooter339

    Joined:
    Nov 8, 2012
    Posts:
    45
    Thanks for the help.
     
  18. ubiquity

    ubiquity

    Joined:
    Jul 13, 2013
    Posts:
    2
    It's not bad as it is, but it would be even better if instead of just selecting the text it would copy the text to the clipboard straightaway.

    Food for thought!
     
  19. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    646
    Seriously the most annoying thing in the world.

    Here's a small mono project that removes the single lines and converts double lines to single, source and executable in the zip.
    View attachment $RemoveSingleConvertDoubleToSingle.zip

    Some one should make this available online.
     
  20. dmitche3

    dmitche3

    Joined:
    Apr 3, 2014
    Posts:
    24
    Well, I don't believe that the 'code' itself is confused as that would be to personify 'code', so the later is out. "The code is confusing" is better when adding to whom it is confusing but it is acceptable. :)
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
  22. HoangPh

    HoangPh

    Joined:
    Apr 25, 2014
    Posts:
    20
    OMG when i use tags it was when i detect if an object is instantiate or not so mine tags are like 10-20 maybe more tags
    @@ . I wonder if is the right way to use tag. Does anyone code the same thing with me? Thanks for topic it was great.
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    Just to be clear:
    • Code tags are for displaying code on the Forum in a host.
    • These tags are Forum markup indicators so we can read your code posted on the forum.
    • These tags are not meant to be included in your final script.
     
  24. HoangPh

    HoangPh

    Joined:
    Apr 25, 2014
    Posts:
    20
    its akward right?
     
  25. MrYOLO

    MrYOLO

    Joined:
    Sep 22, 2013
    Posts:
    2
    Code (CSharp):
    1. void Update()
    2. {
    3.     Debug.Log("Thankkkkk youuuuuuu");
    4. }
     
  26. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    Well, speaking of copy/paste.... :D
    How come pasting code out of MonoDevelop into a web browser gives me 1000 lines of Japanese characters? :p
    Has always done it with me, and quite often, I have to open the script in WordPad, which means digging through all my folders for it... :D
     
  27. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    You just did... :p
     
  28. mdyusuf

    mdyusuf

    Joined:
    Dec 18, 2014
    Posts:
    9
    This is too helpful script. I have a same problem last some days, so it's helpful for me.
     
  29. peggyp

    peggyp

    Joined:
    Apr 28, 2015
    Posts:
    1
    try it:
    Code (CSharp):
    1. void Start () {
    2.      AdjustCamera();
    3. }
    4. // Update is called once per frame
    5. void Update () {
    6.      AdjustCamera();
    7. }
     
  30. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,521
    Code (csharp):
    1. ℼ佄呃偙⁅呈䱍倠䉕䥌⁃ⴢ⼯㍗⽃䐯䑔䠠䵔⁌⸴‰牔湡楳楴湯污⼯久㸢䠼䵔㹌䈼䑏㹙䘼乏⁔慦散㴠✠潍潮㸧匼䅐⁎瑳汹⁥‽挧汯牯⌺㌳㌶㑡✻㸠慶㱲匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠渦獢㭰⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧琾獥呴浩㱥匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠㰽匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㕦挷〰✻㸠⸱㰰匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠㰻匯䅐㹎䈼⽒㰾偓乁猠祴敬㴠✠潣潬㩲㌣㘳愳㬴‧显湵瑣潩㱮匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠渦獢㭰⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧匾慴瑲⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧☾扮灳⠻☩扮灳笻⼼偓乁㰾剂㸯匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠楔敭⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧⸾⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧琾浩卥慣敬⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧㴾㰨匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠整瑳楔敭⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧⤾㰻匯䅐㹎䈼⽒㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧紾⼼偓乁㰾剂㸯䈼⽒㰾偓乁猠祴敬㴠✠潣潬㩲㌣㘳愳㬴‧显湵瑣潩㱮匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠渦獢㭰⼼偓乁㰾偓乁猠祴敬㴠✠潣潬㩲㐣㐴㐴㬴‧唾摰瑡㱥匯䅐㹎匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠渦獢㭰⤨渦獢㭰㱻匯䅐㹎䈼⽒㰾剂㸯匼䅐⁎瑳汹⁥‽挧汯牯⌺㐴㐴㐴✻㸠㱽匯䅐㹎⼼但呎㰾䈯䑏㹙⼼呈䱍>娀婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚婚䳼巎毄巊ꌰ⤗/[CODE]
    2.  
    3. This is what happens when I copy and paste from Monodevelop into the forum using firefox
     
  31. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    Yea, I get that, I just use wordpad (or, these days, visual studio 2013) when I wish to copy/paste stuff there.
    You also mention that firefox has the issue... I remember google chrome doing the same thing, from what I remember. I stopped using chrome when my battery wouldn't behave itself while it was running... :D
     
  32. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    892
    Yes danish people now speak Japanese
     
  33. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    You mean when copy/paste results in chinese/japanese chars? I get that... :D
    (If you mean one line of text though, that's just as annoying!)
     
  34. Ironmax

    Ironmax

    Joined:
    May 12, 2015
    Posts:
    892
    Unity = mostly danish people . But the forum is maybe made by some asian developers. Hence my joke :p
     
  35. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,869
    :D Yes, well played.

    That copy/paste bug alone is why I switched to VS 2015 for my code editor.