Hello there.
I’m making a game that its combat is RPG like and I want to show a pointer on the characters, abilities menu and enemies on the following order:
- Choose a character
- Choose a ability
- Choose a target enemy
I’m currently able to circle through the characters but I’m failing to make them apear on the abilities list and on the enemies.
Here is my code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BattleManager : MonoBehaviour
{
public bool isPlayerTurn;
public int nEnemies = 2;
public Texture2D pointer;
EnemyManager enemyManager;
enum MenuState
{
ChoosingCharacter,
ChoosingSpell,
ChoosingTarget
}
public Transform [] players;
Character [] playerCharacters;
Character currentlySelectedCharacter;
int currentSelectionIndex = 0;
float menuInputTimer;
MenuState currentMenuState;
Vector2 pointerPosition;
// Use this for initialization
void Start ()
{
playerCharacters = new Character[players.Length];
for (int i = 0; i < players.Length; ++i)
{
playerCharacters _= players*.GetComponent<Character>();*_
* }*
* enemyManager = FindObjectOfType();*
* }*
* // Update is called once per frame*
* void Update ()*
* {*
* if (menuInputTimer > 0)*
* {*
* menuInputTimer -= Time.deltaTime;*
* }*
* else*
* {*
* if (Input.GetAxisRaw(“Vertical”) > 0)*
* {*
* currentSelectionIndex ++;*
* menuInputTimer = 0.1f;*
* }*
* else if (Input.GetAxisRaw(“Vertical”) < 0)*
* {*
* currentSelectionIndex --; *
* menuInputTimer = 0.1f;*
* }*
* switch(currentMenuState)*
* {*
* case MenuState.ChoosingCharacter:*
* if (currentSelectionIndex >= playerCharacters.Length)*
* {*
* currentSelectionIndex = 0;*
* }*
* else if (currentSelectionIndex < 0)*
* {*
* currentSelectionIndex = playerCharacters.Length - 1;*
* }*
* //Calculate where on screen the current selected player is*
* pointerPosition = Camera.main.WorldToScreenPoint(players[currentSelectionIndex].position);*
* if (Input.GetButtonDown(“Select”))*
* {*
* currentlySelectedCharacter = playerCharacters[currentSelectionIndex];*
* currentMenuState = MenuState.ChoosingSpell;*
* currentSelectionIndex = 0;*
* }*
* break;*
* case MenuState.ChoosingSpell:*
* if (currentSelectionIndex >= currentlySelectedCharacter.spells.Length)*
* {*
* currentSelectionIndex = 0;*
* }*
* else if (currentSelectionIndex < 0)*
* {*
* currentSelectionIndex = currentlySelectedCharacter.spells.Length - 1;*
* }*
* if (Input.GetButtonDown(“Cancel”))*
* {*
* currentMenuState = MenuState.ChoosingCharacter;*
* currentSelectionIndex = 0;*
* }*
* if (Input.GetButtonDown(“Select”))*
* {*
* currentMenuState = MenuState.ChoosingTarget;*
* currentSelectionIndex = 0;*
* }*
* break;*
* case MenuState.ChoosingTarget:*
* if(currentSelectionIndex >= enemyManager.enemies.Length)*
* {*
* currentSelectionIndex = 0;*
* }*
* else if (currentSelectionIndex < 0)*
* {*
* currentSelectionIndex = enemyManager.enemies.Length - 1;*
* }*
* break;*
* }*
* }*
* }*
* void OnGUI()*
* {*
* switch(currentMenuState)*
* {*
* case MenuState.ChoosingCharacter:*
* GUI.DrawTexture(new Rect(pointerPosition.x + 30, Screen.height - pointerPosition.y, pointer.width, pointer.height), pointer);*
* break;*
* case MenuState.ChoosingSpell:*
* int maxAbilityWidth = Screen.width / currentlySelectedCharacter.spells.Length;*
* for (int i = 0 ; i < currentlySelectedCharacter.spells.Length; ++i)*
* {*
_ GUI.Button(new Rect(i * Mathf.Min(maxAbilityWidth, 100) + 700, Screen.height - 100, Mathf.Min(maxAbilityWidth, 100), 50)
,currentlySelectedCharacter.spells*.name);
}*_
* break;*
* case MenuState.ChoosingTarget:*
* GUI.DrawTexture(new Rect(pointerPosition.x + 30, Screen.height - pointerPosition.y, pointer.width, pointer.height), pointer);*
* break;*
* }*
* }*
}
I’m trying to make the code as generic as I can.
Thanks in advance.