Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by chrisall76 · Jan 10, 2015 at 06:44 AM · c#3dgameplay

Best Way To Handle Multiple Moves (Like Pokemon)?

Hi all, need a bit of help with this. I want to basally have monsters that can pull from a giant list of all available moves to put in their available moves list, which then i can refer to when I need to use the attack for it's info. I'm having a problem with seeing how I could do this, and the solution I'm working with right now is limited (such as I can refer forward but not back, meaning I can't have cooldown on moves). What's the best way to approach this?

Current Setup:

Class used when using a move:

 using UnityEngine;
 using System;
 using System.Reflection;
 using System.Collections;
 using System.Collections.Generic;
 
 public class MonsterMoves : MonoBehaviour, IAbility{
 
     public List<MoveInfo> Moves = new List<MoveInfo>();
 
     public void Use(string MoveName, Vector3 Pos, Quaternion Rot){
         Debug.Log ("Used " + MoveName + "!");
         MethodInfo mi = this.GetType().GetMethod("Use" + MoveName);
         mi.Invoke (this, new object[] {"Ember", Pos, Rot});
     }
 
     public void UseEmber(string MoveName, Vector3 PosToStart, Quaternion Rot){
         ProjectileAttk (MoveName, PosToStart, Rot);
     }
 
     //Attk Types
     public void ProjectileAttk(string MoveName, Vector3 PosToStart, Quaternion Rot){
         GameObject temp = (GameObject) Instantiate (Moves[0].ParticleEffect, PosToStart, Rot);
         temp.audio.clip = Moves[0].SoundEffect;
         temp.audio.Play ();
     }
 }
 
 public interface IAbility {
     //Fill this with all the move types (projectile, transformation, etc)
     void Use(string MoveName, Vector3 Pos, Quaternion Rot);
     void ProjectileAttk (string MoveName, Vector3 Pos, Quaternion Rot);
 }
 
 [System.Serializable]
 public class MoveInfo{
     public string Name;
     public float CooldownTime;
     public GameObject ParticleEffect;
     public AudioClip SoundEffect
 }

How I refer to use a move currently (In the monster class):

     GameObject.FindGameObjectWithTag("MainStuff").GetComponent<MonsterMoves>().Use (KnownMoves[AttkNum], transform.position, transform.rotation);
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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Stardog · Jan 10, 2015 at 09:58 AM

To make a massive list of every ability, you could make a static Dictionary, and use the unique string to get the info about that ability. That will only work if Pokemon are using the exact moves from this dictionary. If you have instantiated/copied the moves they will be different, but if the Pokemon are referencing the moves from the Dictionary, they will be the same.

I would have an Abilities component on every Pokemon, which holds a list of 4 moves/abilities (List abilities).

 public class Abilities : Monobehaviour {
 
     public List<Ability> abilities;

     public void AddMove(string dictionaryKeyID)
     {
         // Code that checks you don't already have 4 moves, etc, etc

         // Add move - using its unique string in the dictionary.
         abilities.Add(AbilityDatabaseScript.abilityDictionary[dictionaryKeyID]);
     }
 
 }

Now you can add moves like Addmove("tackle");

Each ability would have its own abstract base script:

 public abstract class Ability : Monobehaviour {
 
     public string _name;
     public string _description;
     public int _baseDamageAmount;
     public AudioClip _soundEffect;
     // Other vars that EVERY ability will have
 
     public abstract IEnumerator DoAbility(Pokemon target);
 
 }

Then the ability itself with unique DoAbility code.

 public class Tackle : Ability {
 
     public override IEnumerator DoAbility(Pokemon target)
     {
         // Your battle system will have to run this function, without even knowing what the move is. The battle system will also play the audio, animations, etc.
     }
 
 }
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 chrisall76 · Jan 10, 2015 at 11:27 AM 0
Share

This is a nice solution, thanks for the help. Want to make sure though, so each move I add to the game I just create a new class for it in the same script that I created the Tackle, right?
A look at my code now :
http://hastebin.com/uvacebuvum.vala
http://hastebin.com/cubediquwi.vala
http://hastebin.com/ihazagebet.vala

avatar image Cryonize · Jul 18, 2016 at 09:42 AM 0
Share

Could you tell me how you'd put the skills in the dictionary? Say your Tackle ability for example.

avatar image
0

Answer by AwesumeOne · Jan 10, 2015 at 08:57 AM

You could try to Enum the moves? Each move have a few values set to them, such as attack power, defense power. The cooldown could be set to each move as well, just ones that don't need it have it set to zero.

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

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

28 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Add force on the ball based in Mouse Drag 0 Answers

How to build a road? 1 Answer

Having trouble with grid movement 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