Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LeonardoCoV · Oct 03, 2016 at 09:37 PM · c#2d gamenull reference exceptionrpg-game

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:

  1. The game being on center of city.

  2. 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)

  3. 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).

  4. Walking away on "World Map" until enter on battle.

  5. On battle when being first appear intro (GUI BOX, announcement of the battle); second player turn.

  6. On player turn: first select weapon on Command Bar; second select the target and attack.

  7. 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.

and if anyone need more information here my face and steam

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image doublemax · Oct 14, 2016 at 01:14 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

248 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges