Methods debugging, working methods of get and set methods, difference between method and property and use cases of datatypes using methods in C# for Unity
2 min readDec 4, 2022


I learned about Methods debugging, working methods of get and set methods, difference between method and property and use cases of datatypes using methods…
4th Program:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
private int _playerHealth = 100;
public int PlayerHealth
{
get
{
return _playerHealth;
}
set
{
_playerHealth = value;
}
}
private void Start()
{
TakeDamage(50);
Debug.Log(PlayerHealth);
}
void TakeDamage(int damage)
{
PlayerHealth -= damage; // PlayerHealth = PlayerHealth - damage;
}
int ShowDamage() // Returns data
{
PlayerHealth -= 10;
return PlayerHealth;
}
bool ShowDaamage()
{
return true;
}
}
From above program:
private void Start()
{
}
- It is private method called Start and this is builtin method inside MonoBehaviour…
private void Start()
{
TakeDamage(50);
Debug.Log(PlayerHealth);
}
void TakeDamage(int damage)
{
PlayerHealth -= damage;
}
- At first this [TakeDamage(50)] 50 will be assigned to void TakeDamage(..here..) then in void TakeDamage(int damage)
- PlayerHealth -= damage; → Here the value entered in TakeDamage(..here..) assigns in value of damage…So PlayerHealth = 100–50 i.e. 50…
void TakeDamage()
{
PlayerHealth -= damage; // PlayerHealth = PlayerHealth - damage;
}
- () shows that TakeDamage is a method not a property…
- It doesnot return data but it does something…
int ShowDamage()
{
PlayerHealth -= 10;
return PlayerHealth;
}
- int ShowDamage() → Returns data…
- PlayerHealth -= 10 → 10 or integer cuz ShowDamage is a method that returns integer…
click here to follow me in LinkedIn for more updates…
click here to follow me in GitHub for more updates…