conditional statements and it’s use cases in C# for Unity

Karuna Ketan
2 min readDec 5, 2022

I learned about conditional statements and it’s use cases…

5th Program:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
private int _playerHealth = 100;
private int _playerShield = 50;

public int PlayerHealth
{
get
{
return _playerHealth;
}

set
{
_playerHealth = value;
}
}
public int PlayerShield
{
get
{
return _playerShield;
}

set
{
_playerShield = value;
}
}

private void Start()
{
Debug.Log("You took " + DamageTaken(100) + " damage!");
}

int DamageTaken(int damage)
{
int damageTaken;

if (damage < PlayerShield)
{
Debug.Log("Shield not destroyed!");
damageTaken = 0;
}

else if (damage == PlayerShield)
{
Debug.Log("Shield destroyed!");
damageTaken = 0;
}

else
{
Debug.Log("Shield destroyed and damage taken!");
damageTaken = damage - PlayerShield;
}

/*if(damage < PlayerShield || damage == PlayerShield)
{
Debug.Log("Shield not destroyed!");
damageTaken = 0;
}
*/


return damageTaken;
}

}

That’s all…Nothing to explain today😅. Sorry…

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