Ive been banging my head on this one for 2 days now. This method searches through my object pool and ‘trys’ to compare strings with the passed parameter ‘effect’. There are two if statements in the for loop that do the exactly the same thing and that’s just me trying to get one of them to work and both of them log twice in the console like they are both equal and not-equal. i just need to compare one of the other not both . Do i need a return; some where? Do i need a break;? nothing ive tried seems to work. Thanks
public void CheckForStatusEffectInPool(Item effect, Transform recipient)
{
Debug.Log(effect.name);
statusEffect = effect;
newRecipient = recipient;
statusEffectPool = statusEffectPoolParent.GetComponentsInChildren<Transform>();
for (int i = 0; i < statusEffectPool.Length; i++)
{
if (statusEffectPool*.gameObject.name == statusEffect.prefab.gameObject.name)*
There are a couple of things you should try to get more information about why this is happening. My guess is that statusEffectPool has multiple elements when this runs, because the if/else should be exclusive. Try the following:
Add a Debug.Log just inside the for loop when it begins and log the value of i.
Just above the if statement in question, add a Debug.Log statement that logs out the names that are being compared.
You can Debug.Log just about any simple value, so if your code is following unanticipated routes, logging the values will help you understand why the code took a particular turn. Hope that helps, let us know what you find out!
you can use a Else If for the second if. This way, if the first one is true, it will run the code inside and jump to the end of the entire if statement, if the first if is false, it will try the else if, if its true, it runs the code inside and jump to the end, if its false it will run the else and jump to the end
I understand things better if I know exactly what the program is doing, but I saw this line:
if (string.Equals(statusEffectPool*.name, effect.name))*
and couldn’t help but wonder why you’re not doing: if (statusEffectPool*.name == effect.name))* Maybe string.equals is doing something funky with your code? You can’t go wrong with good old conditional operators (==,!=,etc)