C
C#2y ago
Kevin_

❔ Stats

I had a quick question. Is there a way to find a specific scriptable object? I'm working on stats system for a 2D project in Unity but currently when I pickup a stat it adds all of their modifiers regardless if its the right stat or not. I'm using a Event which sends the objectName on pickup to this function
private void HandleObjectAddedToInventory(string objectName)
{
if (objectName == "Health Buff")
{
_playerStats.maxHealth = _modPickUp.mod.modifyAmount;
_playerStats.currentHealth = _playerStats.maxHealth;
}
}
private void HandleObjectAddedToInventory(string objectName)
{
if (objectName == "Health Buff")
{
_playerStats.maxHealth = _modPickUp.mod.modifyAmount;
_playerStats.currentHealth = _playerStats.maxHealth;
}
}
13 Replies
phaseshift
phaseshift2y ago
$xy
MODiX
MODiX2y ago
The XY Problem
Asking about your attempted solution rather than your actual problem
Kevin_
Kevin_OP2y ago
The solution I'm looking to achieve is if I pickup say the Health Buff it only get's the Health Buffs modifyAmount rather than another stats amount.
phaseshift
phaseshift2y ago
Your current snippet doesn't show what's going wrong
Kevin_
Kevin_OP2y ago
Does this help?
private void HandleObjectAddedToInventory(string objectName)
{
if (objectName == "Health Buff")
{
_playerStats.maxHealth = _modPickUp.mod.modifyAmount;
_playerStats.currentHealth = _playerStats.maxHealth;
}
if (objectName == "Damage Buff")
{
_playerStats.bulletDamage += _modPickUp.mod.modifyAmount;
}
}
private void HandleObjectAddedToInventory(string objectName)
{
if (objectName == "Health Buff")
{
_playerStats.maxHealth = _modPickUp.mod.modifyAmount;
_playerStats.currentHealth = _playerStats.maxHealth;
}
if (objectName == "Damage Buff")
{
_playerStats.bulletDamage += _modPickUp.mod.modifyAmount;
}
}
phaseshift
phaseshift2y ago
Not really. You're basically suggesting if is broken
Kevin_
Kevin_OP2y ago
So basically, if I pick up the Damage Buff stat it also adds its modify amount to the maxHealth. I'm trying to figure out a way to separate the two so when I pick up the Damage Buff it does not also add that amount to the maxHealth. Sorry I suck at explaining things
phaseshift
phaseshift2y ago
So are you showing code that doesn't work, or an idea you think might work?
Kevin_
Kevin_OP2y ago
That doesn't work at the moment
phaseshift
phaseshift2y ago
What you're showing can't be the problem (on its own)
Lumu
Lumu2y ago
Quick thing, have you tried printing out the objectName to console right before the if statements to be sure they actually match? Is the specific issue that the if statements aren't being triggered right now?
Kevin_
Kevin_OP2y ago
Yes, I've done that. Umm.... really weird I restarted the editor and um... it seems to be working as intended Before it would add the Damage buff to the players health for some reason but uhhh not anymore I guess.... Lol nothing changed from the code I don’t understand what caused the issue but 🤷
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server