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

Karuna Ketan
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…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Karuna Ketan
Karuna Ketan

Written by Karuna Ketan

Game Designer and Developer | Unity, Unreal Engine, Blender

No responses yet

Write a response