Enemy target reference issue
Hello I'm learning Unity and now I making a 2D RPG only to learn, but I getting some problems with battle turn, well to do my quest I need explain more on this 7 steps:
The game being on center of city.
And need go to shop (little house on right of city) and buy one weapon (all ok, but if you see on inventory the item position is wrong but it's fine, I don't make anything for inventory bag until now)
Leave the city (left side of city, don't have any references yet, only box collider on the final of background image and a GUI how's appear asking if you wanna travel).
Walking away on "World Map" until enter on battle.
On battle when being first appear intro (GUI BOX, announcement of the battle); second player turn.
On player turn: first select weapon on Command Bar; second select the target and attack.
Enemy attack now and after the player turn again, until the end of battle.
ok with this I can show some thing on my game is ok (only for bad for items on bag and command bar) but on second turn of player on the battle when I go select the enemy to attack the target reference is lost ON SECOND turn, and I don't know why, the battle use basic 4 scripts (without the inventory scripts) the "BattleManager.cs", "EnemyController.cs", "CommandBar.cs" and "CommandButton.cs", all 3 scripts are children of BattleManager script and CommandButton is children of CommanBar two of this code have some mass of code to post here, so I will link on dropbox the SCRIPTS(only scripts) and the ASSETS (<-- 6Mb please), and don't be worry I have goods patterns.
Ok what I can explain about this scripts...
1.First when being the battle the GameObject on hierarchy of scene "BattleManager" will start a animator and there have the battle states. The battle states hash is saved on enum in "BattleState.cs" (scripts/class) in order, on "BattleManager" we have two switch how get the current battle state and do some thing with OnGUI() or Update() or both, on the Animator/Code how control the turns and the end of battle is the "Change_Control" state, and is simple if(!attacking){enemy turn}else{player turn} anything of both end battle seeing if have enemy or if the player health < 1.
2.If is player turn, PlayerTurn bool is set to true and until player don't selected weapon and enemy the player can't set the PlayerReady bool to true for can attack did this and PlayerReady true need click on target or on attack GUI to start the coroutine of player attack, ended the coroutine PlayerTurn is set to false and attacking too, Change_Control go to enemy (have only goblins xD) setting EnemyTurn to true and only start coroutine of the enemy attack and ended this EnemyTurn to false and attacking to true and back to player turn again and when you select the target get and lost the reference.
if anyone can help please I'm glad!
and sorry about my poor English.
I didn't even read this completely, because a description of code in words is useless most of the time. Why? Because you will explain what you think you coded. But if something doesn't work like it should, it usually means that you coded something different.
In other words: Try to strip down the code as much as possible and then post the code.
Your answer
Follow this Question
Related Questions
How can I reset the score counter? 2 Answers
how to disable dontdestroyonload on a specific scene 2 Answers
2D AI movement 0 Answers
Selecting a game object in Unity 2d 3 Answers
How to make an enemy 2d chasing player? 2 Answers