Need help with combo based game input and damage systems.
Hi I'm new to using unity and still trying to grasp the key concepts. I have been trying to make a simple combo based game where a random combo (out of 6 possible combos) will show on the screen (each of which is a image attached to a game object on canvas). the player must then complete the combo without error within a given time to deal damage to the enemy. If they cannot the player will take damage and a new combo will be shown. I have been testing with just one combo and cannot seem to get it right. Any help and guidance would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ComboBreaker : MonoBehaviour {
public GameObject Set1P;
public GameObject Set2P;
public GameObject Set3P;
public GameObject Set4P;
public GameObject Set5P;
public GameObject Set6P;
public GameObject Set1E;
public GameObject Set2E;
public GameObject Set3E;
public GameObject Set4E;
public GameObject Set5E;
public GameObject Set6E;
public int PlayerHP = 5;
public int EnemyHP = 5;
public KeyCode[] combo;
public int currentIndex = 0;
void Start()
{
//StartCoroutine(functionName());
Set1P = GameObject.FindGameObjectWithTag("S1P"); // Get all Combo Sets s1p= Set One Player/ s1e = Set One enemy
Set2P = GameObject.FindGameObjectWithTag("S2P");
Set3P = GameObject.FindGameObjectWithTag("S3P");
Set4P = GameObject.FindGameObjectWithTag("S4P");
Set5P = GameObject.FindGameObjectWithTag("S5P");
Set6P = GameObject.FindGameObjectWithTag("S6P");
Set1E = GameObject.FindGameObjectWithTag("S1E");
Set2E = GameObject.FindGameObjectWithTag("S2E");
Set3E = GameObject.FindGameObjectWithTag("S3E");
Set4E = GameObject.FindGameObjectWithTag("S4E");
Set5E = GameObject.FindGameObjectWithTag("S5E");
Set6E = GameObject.FindGameObjectWithTag("S6E");
}
void Update()
{
if(EnemyHP > 0 || PlayerHP > 0)
{
System.Random rand = new System.Random();//get random variable for set
int set = rand.Next(1, 2); // random between 1 and 6, only using one to test with
if (set == 1) // Random = 1, Show Set 1 and complete there will be 6
{
Set1P.SetActive(true); // Set Active both set 1's
Set1E.SetActive(true);
Set2E.SetActive(false);
Set3E.SetActive(false);
Set4E.SetActive(false);
Set5E.SetActive(false);
Set6E.SetActive(false);
Set2P.SetActive(false);
Set3P.SetActive(false);
Set4P.SetActive(false);
Set5P.SetActive(false);
Set6P.SetActive(false);
int AIspeed1 = rand.Next(1, 4); // time between 1 and 3 sec/key
int AIspeed2 = rand.Next(1, 4);
int AIspeed3 = rand.Next(1, 4);
int AIspeed4 = rand.Next(1, 4);
float AIcomplete = AIspeed1 + AIspeed2 + AIspeed3 + AIspeed4; // Ai's time to complete combo player must complete faster
AIcomplete -= Time.deltaTime;
if (Input.GetKeyDown(KeyCode.DownArrow) && AIcomplete > 0) // if key correct go to next or take damage
{
if (Input.GetKeyDown(KeyCode.LeftArrow) && AIcomplete > 0)
{
print("Left key pressed");
if (Input.GetKeyDown(KeyCode.UpArrow) && AIcomplete > 0)
{
print("up key pressed");
if (Input.GetKeyDown(KeyCode.RightArrow) && AIcomplete > 0)
{
print("right key pressed");
--EnemyHP;
}
else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
{
--PlayerHP;
}
}
else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.DownArrow))
{
--PlayerHP;
}
}
else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow))
{
--PlayerHP;
}
}
else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.RightArrow))
{
--PlayerHP;
}
if (PlayerHP <=0 || EnemyHP <= 0)
{
GameOver();
}
print("looped");
}
}
}
void GameOver()
{
Time.timeScale = 0;
//set GameOver Active
}
}
Comment