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 /
avatar image
0
Question by lucateil · Jun 25, 2017 at 11:19 AM · c#arraynewbiedictionarycombo

Spell-casting combo system

I am working on a game which has unique spells composed of different elements. There are various elements (eg. water, fire, cold, arcane, shield, earth, life, lightning) and they are each bound to key. My goal is to be able to queue up to three elements and then cast when I click. The spell changes depending on the combination. For example, if I do fire, fire, fire it casts a very damaging fire spell but if I do something like fire, fire, earth it will do a fiery rock with less fire damage but it has some physical damage in the form of a rock now. The most efficient way I can think of accomplishing this is to assign each element to a key. I press three keys and then when ready I press the "cast" key. It would then combine each key into a single string (eg. if I pressed F for fire, E for earth and S for arcane it would combine them into a single string of "FES"). Then it would sort the string albabetically into "EFS" and compare it to a dictionary of all spells and their three letter input string. From there it would know which spell it is and cast it.

I also would like to make it so that there are certain elements which combine to make new elements like water and cold combining to make ice and fire and water combining to make steam. I also want there to be certain elements which can't go together like earth and lightning or arcane and life. That way I can use the opposites to remove an element from the spell. For example if I am making a spell and I press A for arcane, F for fire and I accidentally press E for earth as my final element but I want to remove the earth and replace it with a different element I can press the opposite of earth (lightning) to remove it from the spell.

That is the concept but I don't know how to actually put it into unity in C#. I'm new to C# but I have alot of past python experience

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cbjunior · Jun 25, 2017 at 01:33 PM

From a programmatic perspective, I would recommend making an enum type to represent the different elements, then adding them to a collection type of fixed size. Something like this:

 public static enum ElementType
 {
     FIRE, EARTH, AIR, WATER, LIGHTNING, ARCANE, ICE
 }

You would put this enum into a class that itself reads the key input and adds the respective enum value to a collection, say an ArrayList. Each time an element is added it is checked against the other values in the collection, and if there's a conflict then remove the conflicting element. Once the fire key is pressed, check the current configuration against a static collection of effects and generate the appropriate effect. I don't want to give you too much example code because it's better for you to work through it to learn. I would recommend looming up how enums and collection types work in C#.

Comment
Add comment · Show 2 · Share
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 lucateil · Jun 25, 2017 at 07:53 PM 0
Share

Thanks for the tips!

This is what I have so far

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Spells : $$anonymous$$onoBehaviour {
 
     class Empty
     {}
 
     public ArrayList elementQ = new ArrayList();
 
     public enum ElementType
     {
         WATER, LIFE, SHIELD, COLD, LIGHTNING, ARCANE, EARTH, FIRE
     }
 
     public ElementType elementType;
     // Use this for initialization
     void Start () {
         
     }
 
     void AddElement(ElementType element)
     {
         print(elementQ);
         elementQ.Add(element);
     }
 
     // Update is called once per frame
     void FixedUpdate () {
         
         if (Input.Get$$anonymous$$eyDown("q"))
             AddElement(ElementType.WATER);
 
         else if (Input.Get$$anonymous$$eyDown("w"))
             AddElement(ElementType.LIFE);
 
         else if (Input.Get$$anonymous$$eyDown("e"))
             AddElement(ElementType.SHIELD);
 
         else if (Input.Get$$anonymous$$eyDown("r"))
             AddElement(ElementType.COLD);
 
         else if (Input.Get$$anonymous$$eyDown("a"))
             AddElement(ElementType.LIGHTNING);
 
         else if (Input.Get$$anonymous$$eyDown("s"))
             AddElement(ElementType.ARCANE);
 
         else if (Input.Get$$anonymous$$eyDown("d"))
             AddElement(ElementType.EARTH);
 
         else if (Input.Get$$anonymous$$eyDown("f"))
             AddElement(ElementType.FIRE);
     }
 }

The issue I'm having right now is that when I try to print the contents of the array list it prints this ins$$anonymous$$d

"elementQ" it prints "System.Collections.ArrayList" "UnityEngine.$$anonymous$$onoBehaviour:print(Object)"

I think this is because the contents of the list aren't strings or something along those lines but I can't figure out how to fix it. I tried doing print(elementQ.ToString); but it didn't work.

Any more advice would be greatly appreciated :)

EDIT: I also can't figure out how to compare the items in the list to check if they are conflicting.

avatar image cbjunior · Jun 26, 2017 at 09:16 AM 0
Share

@lucateil You need to enumerate through the items in the ArrayList and check each one, as well as when you want to print. You could also try using a List<> ins$$anonymous$$d because that will allow you to specify a type:

 List<ElementType> elementList = new List<ElementType>();
 
 private void PrintElements()
 {
      if (elementList != null)
      {
           foreach (ElementType e in elementList)
           {
                print (e.ToString ());
           }
      }
 }

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

339 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Checking bool on multiple script instances. 1 Answer

Assigning scriptable objects to dictionary through array? 0 Answers

Development of the shop? 1 Answer

How to send/copy array from dictionary to class and further to list of class 0 Answers

Deleting an Element from an Array. 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