void CheckKeyCode(KeyCode code, int stringIndex) { if (Input.GetKeyDown(KeyCode.Space)) { for (int i = 0; i < 8; i++) { ControlInput.OnStringChange(i, true); } } if (Input.GetKeyUp(KeyCode.Space)) { for (int i = 0; i < 8; i++) { ControlInput.OnStringChange(i, false); } } if (Input.GetKeyDown(code)) { ControlInput.OnStringChange(stringIndex, true); } if (Input.GetKeyUp(code)) { ControlInput.OnStringChange(stringIndex, false); } if (Input.GetKey(code) && ControlInput.IsButtonPressed(stringIndex) == false) { ControlInput.OnStringChange(stringIndex, true); } }
protected IEnumerator TrailHitRoutine(int noteIndex, GameObject trail) { Note note = Player.Song.Notes[noteIndex]; //更新尾带的颜色 trail.GetComponent <Renderer>().material.color = Colors[note.StringIndex]; //按住的特效 ControlInput.GetStringButton(note.StringIndex).transform.Find("Sparks").GetComponent <ParticleEmitter>().emit = true; ControlInput.GetStringButton(note.StringIndex).transform.Find("Sparks").GetComponent <ParticleEmitter>().GetComponent <Renderer>().enabled = true; Vector3 trailScale = trail.transform.localScale; Vector3 trailPosition = trail.transform.localPosition; //只要特定的按钮被按下,必须一直按着直到尾带结束,否则会敲不中 while (ControlInput.IsButtonPressed(note.StringIndex) && Player.GetCurrentBeat() + 1 <= note.Time + note.Length) { //计算尾带的实际距离 float progress = Mathf.Clamp01((1 + Player.GetCurrentBeat() - note.Time) / note.Length); //收缩尾带,调整位置 trail.transform.localScale = new Vector3(trailScale.x, trailScale.y, trailScale.z * (1 - progress)); trail.transform.localPosition = new Vector3(trailPosition.x, trailPosition.y + trailPosition.y * progress, trailPosition.z); yield return(null); } //结束或者没按中隐藏 trail.GetComponent <Renderer>().enabled = false; //取消特效 ControlInput.GetStringButton(note.StringIndex).transform.Find("Sparks").GetComponent <ParticleEmitter>().emit = false; ControlInput.GetStringButton(note.StringIndex).transform.Find("Sparks").GetComponent <ParticleEmitter>().GetComponent <Renderer>().enabled = false; }