I'm trying to make a start on a Spell/Skill system similar to a Moba or MMO from my project where you would press the skill button and see what type of targeting it has then aim (either in an area or at a target) and then "fire" the skill but I am coming really unstuck rather soon into it.
Please also bare in mind I am not asking how to implement X Spell from Y Game I'm looking to understand the structure of a typical spell in a MOBA/MMO not the spells behavior.
I'll try to describe the flow I'm aiming for
Player presses Skill Button One - for simplicity's sake a Standard Fireball
Cursor Changes to show targeting,
-if it was an Aoe it would show the aoe, now this part stays like this until the Player casts or cancels.
The Player casts (left click) - spell is spawned targeting stuff goes away.
The Player cancels (right click) - everything reverts targeting stuff goes away.
This may seem like a really simple problem for some but I am really struggling with step 2
I have no code to show as every time I try something I find something fundamentally wrong with it, I'm repeatedly writing awful code because I can't find a starting point for this, in short - 'I don't get it'.
Would I use a state-machine and if-so where? Would it not get gradually more complex each with every new spell type? I'm a fan of doing this in a component based style but that right now is irrelevant if I can't understand the basic concept of it.
Apologies, I don't have the technical vocabulary to ask this is in a straight forward, concise way. If code is really necessary I can copy in my last attempt but I believe that would just lead people to think I want to fix the un-fixable.
edit: Added EntitySKillUser and Base_Skill
EntitySkillUser
using System.Collections; using System.Collections.Generic; using UnityEngine; public class EntitySkillUser : MonoBehaviour { public GameObject target = null; public Skill[] skills; private Transform castLocation; private Projector projector; private void Start() { castLocation = transform.Find("castLocation"); projector = castLocation.gameObject.GetComponent<Projector>(); projector.enabled = false; //set up a dummy spell skills = new Skill[1]; skills[0] = new Skill("Test", 2, 5, TargetType.SINGLE); } void Update () { ///problem here only works when Imholding the button down - yes I know about getButtonDown and getButton //I want this to go into "targeting" mode when the buttons pressed wait for a left click to confirm THEN cast // if (InputManager.AbilityButtonOne()) { if (target == null) { //how do I set each unqie targeting type for each spell without having to do something like this for each in the EntitySkillUser projector.enabled = true; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; LayerMask layerMask = LayerMask.NameToLayer("Terrain"); int layer = (1 << layerMask); //set projectorposition if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { Vector3 pos = new Vector3(hit.transform.position.x, 6f, hit.transform.position.z); projector.transform.position = pos; } RaycastHit hitTwo; if (Physics.Raycast(ray, out hitTwo, Mathf.Infinity)) { if (Input.GetMouseButton(0)) { //set target if (hitTwo.collider.GetComponent<Enemy>()) { target = hitTwo.collider.gameObject; } } else if (Input.GetMouseButtonDown(1)) { //cancel } } } else { Debug.Log("have target " + target.name ); } } } } Base_Skill
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Base_Skill { public string name; public int apCost; public int range; public TargetType targetType; public Base_Skill(string name, int apCost, int range, TargetType targetType) { this.name = name; this.apCost = apCost; this.range = range; this.targetType = targetType; } } public enum TargetType { SINGLE, AOE, MULTI }