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 OtreX · Oct 15, 2015 at 06:12 PM · enumdictionaryspace shootertargetting

Using a dictionary of two enums

Well, I'm making a space shooter. Sometimes my ships create a formation. They do this by targeting a gameobject MainFormationObject that stores an array of empty gameobject WayPoints. The ships target the MainFormationObject and this object tells the ship which WayPoint will it target. For the sake of keeping it short, I'll call the ship that is targetting the leader waypoint the Leader and the ships that are targeting the escort waypoints the Escorts. Now I'm trying to break the formation when certain conditions are met (by breaking the formation I mean: tell the ships to not target these WayPoints anymore / change their target).

Basically, in the inspector I want a way of having the drop down menus for "What triggers the break of the formation" and then selecting by another drop down menu "How does the formation breaks" so its kind of user friendly.

I thought of using two enums for that. The enums would look something like this:

1) What triggers the break of the formation {

leader gets fired at,

escort gets fired at,

leader dies,

escort dies,

formation changes target,

formation's target gets destroyed }

and

2) How does the formation breaks {

escorts will target the ship that is firing at leader (only used if the leader is getting fired at),

make all the ships get a different target,

leader gets a different target,

escorts get a different target,

do nothing }

I didnt know how to link one enum (lets call it the battleEvent) to the other enum (lets call it the reaction), but I asked on a different topic and I found out about dictionaries and using this code structure I was able to throw in a key to the dictionary (the battleEvent) and make it spit a value (the reaction) but then I don't know what to do with it.

          public enum BattleEvent
          {
              LeaderFiredAt,
              EscortFiredAt,
              LeaderDied,
              EscortDied,
              FormationTargetChanged,
              FormationTargetDestroyed
          }
      
          public enum Reaction
          {
              DefendLeader,
              FireAtWill,
              LeaderRetarget,
              EscortRetarget,
              None 
          }
      
          public Reaction LeaderFiredAtReaction;
          public Reaction EscortFiredAtReaction;
          public Reaction LeaderDiedReaction;
          public Reaction EscortDiedReaction;
          public Reaction FormationTargetChangedReaction;
          public Reaction FormationTargetDestroyedReaction;
      
          public Dictionary<BattleEvent, Reaction> ReactionMap = 
              new Dictionary<BattleEvent, Reaction>();
      
          void Start () {
              ReactionMap.Add(BattleEvent.LeaderFiredAt, LeaderFiredAtReaction);
              ReactionMap.Add(BattleEvent.EscortFiredAt, EscortFiredAtReaction);
              ReactionMap.Add(BattleEvent.LeaderDied, LeaderDiedReaction);
              ReactionMap.Add(BattleEvent.EscortDied, EscortDiedReaction);
              ReactionMap.Add(BattleEvent.FormationTargetChanged, FormationTargetChangedReaction);
              ReactionMap.Add(BattleEvent.FormationTargetDestroyed, FormationTargetDestroyedReaction);
          }
          
          public Reaction GetReactionTo(BattleEvent bEvent)
          {
              var react = Reaction.None;
              ReactionMap.TryGetValue(bEvent, out react);
              return react;
          }

I have code for the reactions (as an instance: making the Leader target something else, and all the others) but I dont know where to put it. Can you give me a hand with some pseudocode?

Thank you in advance for your time :)

Comment
Add comment
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

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

30 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

Related Questions

Enum comparison C# 1 Answer

Active and Inactive Spawn Points 0 Answers

Pulling and printing a random entry from a dictionary of a list of strings. C#. 1 Answer

I have some problem with dictionary and loading the scene. 0 Answers

Player target enemies automatically 0 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