Skip to content
Snippets Groups Projects
Commit 22094180 authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Made it so xp or hp bar being null doesn't throw errors.

parent 526d5869
No related branches found
No related tags found
1 merge request!30Improvements to attacks.
......@@ -48,13 +48,13 @@ namespace BigSock {
{
base.Start();
xpBar.SetMaxXp(maxXp);
xpBar.SetXp(xp);
xpBar?.SetMaxXp(maxXp);
xpBar?.SetXp(xp);
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
hpBar.SetMaxHealth(Convert.ToInt32(MaxHP));
hpBar.SetHealth(Convert.ToInt32(HP));
hpBar?.SetMaxHealth(Convert.ToInt32(MaxHP));
hpBar?.SetHealth(Convert.ToInt32(HP));
//!! DEBUG: Add item to player at start to test if it works.
TryPickUpItem(ItemService.SINGLETON.Get(201));
......@@ -173,13 +173,13 @@ namespace BigSock {
*/
protected override void AfterDamage(IAttackStats attack) {
base.AfterDamage(attack);
hpBar.SetHealth(Convert.ToInt32(HP));
hpBar?.SetHealth(Convert.ToInt32(HP));
}
public void GainXp(float xp){
GiveXp(xp);
CheckXp();
xpBar.SetXp(this.xp);
xpBar?.SetXp(this.xp);
}
private void CheckXp(){
......@@ -187,7 +187,7 @@ namespace BigSock {
level += 1;
xp -= maxXp;
maxXp = (level + 1) * 100;
xpBar.SetMaxXp(maxXp);
xpBar?.SetMaxXp(maxXp);
}
}
......
fileFormatVersion: 2
guid: af58fad506f36bf4e99a1ca592acc21f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment