UnityBlankProject

Useful Code Snippets

Controlling Shader Graph from script

 [SerializeField]
 Material mat_DissolveMaterial;
    
 IEnumerator Dissolve()
    {
        float counter = 1;
        while (counter > -1)
        {
            counter -= Time.deltaTime;
            yield return new WaitForSeconds(0.01f);
            mat_DissolveMaterial.SetFloat("Vector1_7C06CC4A", counter);
        }
    }

Filling Images

 void FillBar(Image img, int value, int originalValue)
  {
    float newValue = (float)value / originalValue;
    img.fillAmount = newValue;
  }

  IEnumerator FillWithTime(Image img, float sec)
  {
    float counter = 0;

    while (counter < sec)
    {

      counter += Time.deltaTime;
      img.fillAmount = counter / sec;
      yield return null;
    }

  }

Particles effects on hit

#region Public GameObjects
    [SerializeField] 
    private GameObject go_ParticlePrefab;
#endregion

#region Private GameObjects
    private ParticleSystem ps_OnHitParticleSystem;
    private ParticleSystem ps_System;
#endregion

//In Start Method
        ps_OnHitParticleSystem = go_ParticlePrefab.GetComponent<ParticleSystem>();
        ps_System = Instantiate(ps_OnHitParticleSystem);
        ps_System.transform.position = transform.position;
        ps_System.transform.SetParent(transform);
//OnCollision
    ps_System.Play();

Conventions & Rules

  1. ALWAYS use descriptive Variables and Methods:
int i_PrimaryWeaponAmmo = 30;
int i_SecondaryWeaponAmmo = 40;

void Start()
{
    IntializeAmmunations();
}
  1. Use PascalCase for Variables:
Transform t_PilotTransform;
GameObject go_PilotGameObject;
int i_PilotHP;
  1. Use small letters abbreviations to describe Variables ..* go_ for GameObject
    ..* t_ for Transform
    ..* i_ for int
    ..* Is for Bool
    ..* f_ for float
    ..* p_ for Pilot
    ..* titan_ for Titan
    ..* wep_ for Weapon
    ..* ability_ for Weapon
    ..* ui_ for anything related to UI
    ..* anim_ for Animator
    ..* audioSource_ for AudioSources
    ..* audioClip_ for AudioClip
    ..* l_ for any lists and arrays (l_go_ , l_p__)
    ..* _- for any static Variable (_go , _p)
Transform t_PilotTransform;
GameObject go_PilotGameObject;
int i_PilotHP;
bool IsHit;
Weapon wep_PilotPrimaryWeapon
GameObject[] l_go_Enemies
Tranforms[] l_t_TitanPositions
static Pilot __p_MainPilot
  1. Use PascalCase for Methods:
GetHit()
{
  Debug.Log("I'm HIT");
}

WallRide()
{

}
  1. Use CamelCase for Methods Parameters:
GetHit(int index)
{
  Debug.Log("I'm HIT" + index);
}

WallRide(Transform targetWall)
{
    targetWall.position = null;
}
  1. Use [SerializeField] instead of public to show Variables in inspector:
[SerializeField]
private Transform t_PilotTransform;

[SerializeField]
public int i_PilotHP;
  1. Use regions to organise every block of your code:
#region Variables
int HP;
#endregion
  1. There will be a Singleton in every script for the PlayerPilot, Use it carefully.

  2. You will find your script containing regions, use them and make all your scripts similar to them, also feel free to add more regions.

  3. You will find a SampleScript.cs that contains all of the required regions, you can copy it's if you are going to create a new script.

  4. Everyone of us has his own Structured Sandbox (Scene) to create and test his tasks, Try sticking to the Scene Hierarichy.