C
C#15mo 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
phaseshift15mo ago
$xy
MODiX
MODiX15mo ago
The XY Problem
Asking about your attempted solution rather than your actual problem
Kevin_
Kevin_15mo 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
phaseshift15mo ago
Your current snippet doesn't show what's going wrong
Kevin_
Kevin_15mo 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
phaseshift15mo ago
Not really. You're basically suggesting if is broken
Kevin_
Kevin_15mo 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
phaseshift15mo ago
So are you showing code that doesn't work, or an idea you think might work?
Kevin_
Kevin_15mo ago
That doesn't work at the moment
phaseshift
phaseshift15mo ago
What you're showing can't be the problem (on its own)
Lumu
Lumu15mo 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_15mo 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
Accord15mo 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
More Posts
✅ login registration form not working3 forms __**mainform.cs**__ shows 2 buttons [register](register.cs) [login](login.cs) __**register.✅ Replace regex-pattern with dynamically generated string.I have a text and a regex pattern. I want to take each of the substrings that match the pattern and ❔ Strategy for plugin architecture dependency injectionI am creating an application with simple plugins in which registration information of plugins are st✅ my ui and backend not working together``` private const string ServerUrl = "http://144.24.154.156:5445/api/login"; // replace with your No❔ when using client.PostAsync('...') in a test how do you go about using transactionsAs title❔ Installing System.Threading.Tasks.Dataflow in UnityHi. I'm developing a game in Unity and learning C# for the first time. I'm wondering how I would be ❔ C# Math.Min/Math.Floor & Foreach/forHello, so my problem is quite bizarre, I have two somewhat similar solutions, but my concern impactsgameObject does not re-enable itself in the switch statementso i have a switch statement setup so that depending on the in-game day, a gameobject would appear/d❔ Dynamical Programming to find min cost of supplying cars for 'n' months.Hello everyone, i got an assignment about dynamical programming implementation of a min. cost findin❔ how to run a test to test an endpoint and to check in the database that the data been storedI dont know what the correct way is to do this in aspnet, or if this is how it is done in .net I wa