Object does not work properly unless I select it in the inspector first?
I have been unable to get any help with this bug anywhere so I thought to ask here so my problem: I have a mono Behavior that listens for a few unity events, when it gets one it checks some conditions then runs a function from another script. The Bug? well when I hit play mode the script only does some of what it is supposed to, it wont affect variables or show debug messages, but it will invoke events and run other functions. It works PERFECTLY if while the game is playing I select the object holding this script I have:
Reset unity
Reset my computer
Updated Unity
Re imported all assets
Undid most changes in Github
Deleted the object and remade it
Nothing worked, I am at my limit and do not want to have to start from scratch because of something I do not know how to prevent. I am new to unity events so I do not know if that is what is causing the Errors
This is some of the code.. Dont know if this will help as what fixes the Error is in the inspector
//Is called via a event listener when a tile is hovered
private void Targetting(Tile tile)
{
if (selectedSkill != null)
{
if (Input.GetMouseButtonDown(0))
{
if (selectedUnit == null) { selectedSkill = null; return; }
//This check is for testing Im still kinda early on
if (selectedUnit.skills[0] != null) { SelectSkill(selectedUnit.skills[0]);}
if (playerSide.GetTile(selectedTile.x, selectedTile.y) != selectedTile)
{
selectedSkill.UseSkill(selectedTile, selectedUnit);
}
}
}
}
//The Skills Use skill function
public void UseSkill(Tile tile, Unit user)
{
if (usesLeft > 0)
{
List<Unit> targets = data.targetting.GetTargets(tile);
int dmg;
int targetsFound = 0;
foreach (var t in targets)
{
if (t != null)
{
targetsFound++;
//HitChances go Here
dmg = data.CalculateDamage(user, t);
t.HP -= dmg;
Debug.Log( t.Name + " took " + dmg + " damage");
}
}
if (targetsFound == 0) { Debug.Log("No Targets"); return; }
CombatEvents.skillUsed.Invoke(this);
usesLeft--;
}
else
{
Debug.Log(user.Name + "'s " + data.name + " is out of uses");
}
}
Hi, did anyone in this thread find a solution to their issues, I'm running into the same problem and have no idea how to fix it?