Search Unity

Hey weird question.

Discussion in 'Editor & General Support' started by livingwarlock, Jun 24, 2019.

  1. livingwarlock

    livingwarlock

    Joined:
    Jun 2, 2018
    Posts:
    1
    Hey, so as I was coding and I realized that instinctively I add spaces in between my lines of code and was wondering if anyone else does or did the same format as I did and if there was a name for this type of thing.

    Example:
    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class EnemyHealth : MonoBehaviour
    {
    public float HitPoints = 100f;

    public GameObject Zombie;

    //create a public method which reduces hitpoints my method

    public void TakeDamages(float Damage)

    {

    HitPoints -= Damage;

    if (HitPoints <= 0)

    {

    Destroy(Zombie);

    }

    }



    }
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    What you're generally describing is known as Code Formatting, and it covers things like whether you indent with tabs or spaces, whether you put your opening curly braces on the same line as your 'if' statement or on the following line, and a bunch of other controversial topics that software engineers love to debate.

    Note that most IDEs support autoformatting your code according to some basic rules, to keep the code consistently formatted even if multiple developers are working on it.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yuck!

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EnemyHealth : MonoBehaviour
    6. {
    7.  
    8.     public float HitPoints = 100f;
    9.     public GameObject Zombie;
    10.  
    11.     //create a public method which reduces hitpoints my method
    12.     public void TakeDamages(float Damage)
    13.     {
    14.         HitPoints -= Damage;
    15.         if (HitPoints <= 0)
    16.         {
    17.             Destroy(Zombie);
    18.         }
    19.     }
    20.  
    21. }