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 /
This question was closed Jan 22, 2016 at 07:37 AM by Yetter for the following reason:

Solved it myself

avatar image
0
Question by Yetter · Jan 20, 2016 at 10:19 PM · arraydelegatefunction call

Storing delegates or function calls in a array

I've been struggling to figure out the best way to approach this problem. I'm making a turn based game. Every turn the player chooses several actions, so does each enemy in play. These actions should all be stored in an array, shuffled and then executed one at a time during and TurnPlay sequence.

so a action function look this


public void FirePrim(source,weapon,target){
  dmg = HitCalc(weapon,target);
  Instantiate(projectile);
  projectile.GetComponent().dmg = dmg;
}

What I'd like to do is have the function call and parameters wrapped up in one varible that can be added to the actionArray. I'm thinking that delegates may be the way to go, but my knowledge of how they work is limited. I figure I could make a delegate that contains all parameter information and extra instructions if necessary like so

pubic void delegate myDelegate; void firePrimPckg(){ FirePrim(GameObject Player, GameObject Beam, GameObject targetEnemy); }

myDelegate = firePrimPckg;

and this point I'd like to store myDelegate into an array for later use, but from what I can tell a delegate doesn't have a type so I can't store it in a regular array. Should I use an ArrayList? I've been advised against it in the past due to performance issues, Is it possible to store these delegates as strings and then use the Invoke method? Or perhaps there is a better strategy for accomplishing this that I have overlooked. Any help at all would be greatly appreciated :)

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

  • Sort: 

Follow this Question

Answers Answers and Comments

38 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

Related Questions

How do you access the Scripts, Functions, and Bools within an array of GameObjects? 0 Answers

Array index out of range error with onClick.AddListener(delegate) 1 Answer

Storing a Gameobject from array into a Gameobject variable giving NullReferenceException 3 Answers

Fields not populated during OnValidate on Editor startup 2 Answers

Cannot convert UnityEngine.GameObject to UnityEngine.GameObject 1 Answer


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