void Update() { for (int i = 0; i < ControlInput.NumStrings; ++i) { StringChanges[i] = false; } for (int i = 0; i < Input.touchCount; ++i) { Touch touch = Input.GetTouch(i); if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; for (int j = 0; j < ControlInput.NumStrings; ++j) { if (ControlInput.GetStringButton(j).GetComponent <Collider>().Raycast(ray, out hit, Mathf.Infinity)) { StringChanges[j] = true; } } } } for (int i = 0; i < ControlInput.NumStrings; ++i) { ControlInput.OnStringChange(i, StringChanges[i]); } }
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; }