Question by
paulyfam · Feb 28 at 08:04 PM ·
c#unity 2drhythmfightingame
Arrows not registering as a hit with the player 2 script, but working perfectly fine with the p1 script
Hi, I was hoping to get some help with my game... it's a rhythm based fighting game, and the idea is that you'll only attack if you're on beat. It works perfectly fine with the p1 script, but not with the p2 script, and I was hoping to get some ideas on what's wrong. thanks in advance!
//P1 script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ComboManager : MonoBehaviour
{
public List<KeyCode> keyToPress = new List<KeyCode>();
public static ComboManager instance;
Animator animator = new Animator();
public List<string> MegaCombos = new List<string>();
List<KeyCode> cache = new List<KeyCode>();
// Start is called before the first frame update
void Start()
{
instance = this;
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
foreach (KeyCode key in keyToPress)
{
if (Input.GetKeyDown(key))
{
if (NoteObj.pressedPublic)
{
if (Input.GetKeyDown(KeyCode.Comma))
{
animator.Play("Kick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
cache.Add(KeyCode.Comma);
}
if (Input.GetKeyDown(KeyCode.Period))
{
animator.Play("Punch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
cache.Add(KeyCode.Period);
}
if (Input.GetKeyDown(KeyCode.Comma) && Input.GetKeyDown(KeyCode.Period))
{
animator.Play("Gash");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
}
if (cache.Contains(KeyCode.Comma) && Input.GetKeyDown(KeyCode.UpArrow))
{
animator.Play("CraneKick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upComma");
cache.Clear();
}
if (cache.Contains(KeyCode.Period) && Input.GetKeyDown(KeyCode.UpArrow))
{
animator.Play("LadderPunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upPeriod");
cache.Clear();
}
if (cache.Contains(KeyCode.Comma) && Input.GetKeyDown(KeyCode.DownArrow))
{
animator.Play("LegSweep");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("downComma");
cache.Clear();
}
if (cache.Contains(KeyCode.Period) && Input.GetKeyDown(KeyCode.DownArrow))
{
animator.Play("GroundedPunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("downPeriod");
cache.Clear();
}
if (cache.Contains(KeyCode.Comma) && Input.GetKeyDown(KeyCode.LeftArrow))
{
animator.Play("RoundhouseKick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("sideComma");
cache.Clear();
}
if (cache.Contains(KeyCode.Period) && Input.GetKeyDown(KeyCode.LeftArrow))
{
animator.Play("DoublePunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("sidePeriod");
cache.Clear();
}
if (cache.Contains(KeyCode.Comma) && cache.Contains(KeyCode.Period) && Input.GetKeyDown(KeyCode.UpArrow))
{
animator.Play("Spear");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upCommaPeriod");
cache.Clear();
}
if (cache.Contains(KeyCode.Comma) && cache.Contains(KeyCode.Period) && Input.GetKeyDown(KeyCode.DownArrow))
{
animator.Play("Spike");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("downCommaPeriod");
cache.Clear();
}
}
//Miss Graphic
else
{
animator.Play("Miss");
}
}
}
//Mega Combos
//Spin
if (MegaCombos.IndexOf("upPeriod") == 0)
{
if (MegaCombos.IndexOf("sideComma") == 1)
{
if (MegaCombos.IndexOf("downComma") == 2)
{
if (MegaCombos.IndexOf("sidePeriod") == 3)
{
animator.Play("Spin");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
}
//Flip
if (MegaCombos.IndexOf("downComma") == 0)
{
if (MegaCombos.IndexOf("downPeriod") == 1)
{
if (MegaCombos.IndexOf("upComma") == 2)
{
animator.Play("Flip");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
//Dive
if (MegaCombos.IndexOf("downPeriod") == 0)
{
if (MegaCombos.IndexOf("downComma") == 1)
{
if (MegaCombos.IndexOf("upComma") == 2)
{
if (MegaCombos.IndexOf("sidePeriod") == 3)
{
animator.Play("CurvePunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
}
}
}
//P2 Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ComboManagerP2 : MonoBehaviour
{
public List<KeyCode> keyToPress = new List<KeyCode>();
public static ComboManagerP2 instance;
Animator animator = new Animator();
public List<string> MegaCombos = new List<string>();
List<KeyCode> cache = new List<KeyCode>();
// Start is called before the first frame update
void Start()
{
instance = this;
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
foreach (KeyCode key in keyToPress)
{
if (Input.GetKeyDown(key))
{
if (NoteObj.pressedPublic)
{
if (Input.GetKeyDown(KeyCode.Z))
{
animator.Play("Kick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
cache.Add(KeyCode.Z);
}
if (Input.GetKeyDown(KeyCode.X))
{
animator.Play("Punch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
cache.Add(KeyCode.X);
}
if (Input.GetKeyDown(KeyCode.Z) && Input.GetKeyDown(KeyCode.X))
{
animator.Play("Gash");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
}
if (cache.Contains(KeyCode.Z) && Input.GetKeyDown(KeyCode.T))
{
animator.Play("CraneKick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upZ");
cache.Clear();
}
if (cache.Contains(KeyCode.X) && Input.GetKeyDown(KeyCode.T))
{
animator.Play("LadderPunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upX");
cache.Clear();
}
if (cache.Contains(KeyCode.Z) && Input.GetKeyDown(KeyCode.G))
{
animator.Play("LegSweep");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6739271f);
MegaCombos.Add("downZ");
cache.Clear();
}
if (cache.Contains(KeyCode.X) && Input.GetKeyDown(KeyCode.G))
{
animator.Play("GroundedPunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("downX");
cache.Clear();
}
if (cache.Contains(KeyCode.Z) && Input.GetKeyDown(KeyCode.H))
{
animator.Play("RoundhouseKick");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("sideZ");
cache.Clear();
}
if (cache.Contains(KeyCode.X) && Input.GetKeyDown(KeyCode.H))
{
animator.Play("DoublePunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("sideX");
cache.Clear();
}
if (cache.Contains(KeyCode.Z) && cache.Contains(KeyCode.X) && Input.GetKeyDown(KeyCode.T))
{
animator.Play("Spear");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("upZX");
cache.Clear();
}
if (cache.Contains(KeyCode.Z) && cache.Contains(KeyCode.X) && Input.GetKeyDown(KeyCode.G))
{
animator.Play("Spike");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Add("downZX");
cache.Clear();
}
}
//Miss Graphic
else
{
animator.Play("Miss");
}
}
}
//Mega Combos
//Spin
if (MegaCombos.IndexOf("upX") == 0)
{
if (MegaCombos.IndexOf("sideZ") == 1)
{
if (MegaCombos.IndexOf("downZ") == 2)
{
if (MegaCombos.IndexOf("sideX") == 3)
{
animator.Play("Spin");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
}
//Flip
if (MegaCombos.IndexOf("downZ") == 0)
{
if (MegaCombos.IndexOf("downX") == 1)
{
if (MegaCombos.IndexOf("upZ") == 2)
{
animator.Play("Flip");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
//Dive
if (MegaCombos.IndexOf("downX") == 0)
{
if (MegaCombos.IndexOf("downZ") == 1)
{
if (MegaCombos.IndexOf("upZ") == 2)
{
if (MegaCombos.IndexOf("sideX") == 3)
{
animator.Play("CurvePunch");
gameObject.transform.position = new Vector3(4.03f, -1.44f, -6.739271f);
MegaCombos.Clear();
}
}
}
}
}
}
//Note/Arrows script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoteObj : MonoBehaviour
{
public bool canBePressed;
public static bool pressedPublic;
KeyCode key;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
foreach (KeyCode key in GameManager.instance.keys)
{
if (Input.GetKeyDown(key))
{
if (canBePressed)
{
canBePressed = false;
pressedPublic = false;
gameObject.SetActive(false);
GameManager.instance.noteHit();
break;
}
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Activator")
{
canBePressed = true;
pressedPublic = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (canBePressed)
{
if (collision.tag == "Activator")
{
canBePressed = false;
pressedPublic = false;
GameManager.instance.noteMiss();
gameObject.SetActive(false);
}
}
}
}
Comment