So i was trying to put all the attacks in a single list of GameObjects. They all have different tags (i use tags to know where to move them, probably not the best approach but it was the best i could find)
I tried Doing a FindGameObjectsWithTag() for all tags and concatenating them together but it gave the
error CS0176: Member 'string.Concat(object, object, object)' cannot be accessed with an instance reference; qualify it with a type name instead
Then i tried calling the members with the tag (so "Directions/Up" instead of EnemyDirections[0]
)
but same error
Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public enum BattleState
{
Start,
PlayerTurn,
EnemyTurn,
FinishedTurn,
Won,
Lost
}
public class TurnHandler : MonoBehaviour
{
List<string> EnemyDirections;
//Player
//Scripts
PlayerHealth PlayerHp;
[SerializeField] PlayerMovement PlayerMove;
//Objects
[SerializeField]GameObject PlayerUI;
GameObject Player;
//Battlestate
public BattleState state;
private bool enemyActed;
//AttacksGoingUp
private GameObject[] EnemyAtcks0;
//AttacksGoingDown
private GameObject[] EnemyAtcks1;
//AttacksGoingLeft
private GameObject[] EnemyAtcks2;
//AttacksGoingRight
private GameObject[] EnemyAtcks3;
//AllAtacks
private GameObject[] EnemyAtcks;
[SerializeField] int Enemies = 1;
public void PlayerAct ()
{
playerfinishTurn();
}
void playerfinishTurn()
{
Player.SetActive(false);
state = BattleState.EnemyTurn;
}
void EnemyFinishedTurn()
{
foreach (GameObject obj in EnemyAtcks)
{
Destroy(obj);
}
enemyActed = false;
state = BattleState.FinishedTurn;
}
void Start()
{
EnemySetDirections();
//Player
Player = GameObject.FindGameObjectWithTag("Player");
//BattleState
state = BattleState.Start;
enemyActed = false;
}
void Update()
{
if (state == BattleState.Start)
{
PlayerUI.SetActive(true);
state = BattleState.PlayerTurn;
}
else if (state == BattleState.EnemyTurn)
{
if (Enemies <= 0 )
{
EnemyFinishedTurn();
}
else
{
if (!enemyActed)
{
if (Player != null)
{
Player.gameObject.SetActive(true);
PlayerMove.SetHeart();
EnemyAtcks0 = GameObject.FindGameObjectsWithTag(EnemyDirections[0]);
EnemyAtcks1 = GameObject.FindGameObjectsWithTag(EnemyDirections[1]);
EnemyAtcks2 = GameObject.FindGameObjectsWithTag(EnemyDirections[2]);
EnemyAtcks3 = GameObject.FindGameObjectsWithTag(EnemyDirections[3]);
EnemyAtcks = EnemyDirections[0].Concat(EnemyDirections[1], EnemyDirections[2], EnemyDirections[3]).ToArray();
enemyActed = true;
}
}
else
{
bool enemyfin = true;
if (enemyfin)
{
EnemyFinishedTurn();
}
}
}
}
else if (state == BattleState.FinishedTurn)
{
Player.SetActive(false);
if (PlayerHealth.HP < 0)
{
state = BattleState.Lost;
}
else
{
state = BattleState.Start;
}
}
else if (state == BattleState.Won)
{
Debug.Log("Hai vinto!");
}
}
void EnemySetDirections()
{
EnemyDirections.Add("Directions/Up");
EnemyDirections.Add("Directions/Down");
EnemyDirections.Add("Directions/Left");
EnemyDirections.Add("Directions/Right");
}
}