// Tap down event void OnTapDown(int id, Vector2 position) { if (!touchMap.ContainsKey(id)) // Protect against double counts { if (common.gameOver) { common.OnTapDown(id, position); } else { // Collision check via raycast Ray ray = Camera.main.ScreenPointToRay(position); RaycastHit hit; // If hit if (Physics.Raycast(ray, out hit)) { // Check tag GameObject hitObject = hit.collider.gameObject; if (hitObject.tag.Equals(Tags.TAPBOX)) { TapboxScript tapbox = hitObject.GetComponent <TapboxScript>(); // Animation tapbox.PlayDownAnim(); // Add to dictionary touchMap.Add( id, tapbox ); // Check for notes OnTapboxTap(tapbox); } } } } }
// Initialize a tapbox TapboxScript InitTapbox(int column, Vector3 position) { GameObject tapboxObject = (GameObject)Instantiate(tapboxPrefab); TapboxScript tapbox = tapboxObject.GetComponent <TapboxScript>(); tapbox.Setup(column); tapboxObject.transform.position = position; return(tapbox); }
// Check for notes hit void OnTapboxTap(TapboxScript tapbox) { int column = tapbox.column; foreach (NotesScript note in notes) { if (note.column == column) { if (note.state == NotesScript.NotesState.ACTIVE) { common.OnNoteHit(note); break; } } } }
// Setup tapboxes and touch input void SetupTapboxes() { //tapboxes = new List<TapboxScript>(); GameObject sliderObject = (GameObject)Instantiate(tapboxPrefab); slider = sliderObject.GetComponent <TapboxScript>(); exSprite sprite = sliderObject.GetComponent <exSprite>(); sprite.scale = new Vector2(SLIDER_WIDTH, SLIDER_HEIGHT); sprite.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta = sliderPositionInit - sliderPositionEnd; }
// Setup tapboxes and touch input void SetupTapboxes() { //tapboxes = new List<TapboxScript>(); GameObject sliderObject_0 = (GameObject)Instantiate(tapboxPrefab); slider_0 = sliderObject_0.GetComponent <TapboxScript>(); exSprite sprite_0 = sliderObject_0.GetComponent <exSprite>(); sprite_0.scale = sliderSizeInit; sprite_0.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta_0 = sliderPositionInit_0 - sliderPositionEnd_0; GameObject sliderObject_1 = (GameObject)Instantiate(tapboxPrefab); slider_1 = sliderObject_1.GetComponent <TapboxScript>(); exSprite sprite_1 = sliderObject_1.GetComponent <exSprite>(); sprite_1.scale = sliderSizeInit; sprite_1.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta_1 = sliderPositionInit_1 - sliderPositionEnd_1; GameObject sliderObject_2 = (GameObject)Instantiate(tapboxPrefab); slider_2 = sliderObject_2.GetComponent <TapboxScript>(); exSprite sprite_2 = sliderObject_2.GetComponent <exSprite>(); sprite_2.scale = sliderSizeInit; sprite_2.color = new Color(1, 1, 1, 0.75f); sliderObject_2.transform.Rotate(new Vector3(0, 0, 90f)); sliderPositionDelta_2 = sliderPositionInit_2 - sliderPositionEnd_2; GameObject sliderObject_3 = (GameObject)Instantiate(tapboxPrefab); slider_3 = sliderObject_3.GetComponent <TapboxScript>(); exSprite sprite_3 = sliderObject_3.GetComponent <exSprite>(); sprite_3.scale = sliderSizeInit; sprite_3.color = new Color(1, 1, 1, 0.75f); sliderObject_3.transform.Rotate(new Vector3(0, 0, 90f)); sliderPositionDelta_3 = sliderPositionInit_3 - sliderPositionEnd_3; sliderSizeDelta = sliderSizeInit - sliderSizeEnd; }
void UpdateNotesList() { // Game over check if (common.gameOver) { return; } // Remove completed notes, assumes sequential removal while (notes.Count > 0 && notes.First.Value.state == NotesScript.NotesState.REMOVE) { // Destroy the tapbox Destroy(notes.First.Value.tapbox.gameObject); // Destroy the note Destroy(notes.First.Value.gameObject); notes.RemoveFirst(); } // Add new notes while (notesIterator.hasNext()) { // If in the look-ahead range if (notesIterator.nextTime() - common.musicTime < CommonScript.TIME_LOOKAHEAD) { GameObject notesObject = (GameObject)Instantiate(notesPrefab); NotesScript note = notesObject.GetComponent <NotesScript>(); notesIterator.next(note); // For grid note.column += rowCount * 4; rowCount++; if (rowCount > 3) { rowCount = 0; } Vector3 position; switch (note.column) { case 0: position = notesPosition_0; break; case 1: position = notesPosition_1; break; case 2: position = notesPosition_2; break; case 3: position = notesPosition_3; break; case 4: position = notesPosition_4; break; case 5: position = notesPosition_5; break; case 6: position = notesPosition_6; break; case 7: position = notesPosition_7; break; case 8: position = notesPosition_8; break; case 9: position = notesPosition_9; break; case 10: position = notesPosition_10; break; case 11: position = notesPosition_11; break; case 12: position = notesPosition_12; break; case 13: position = notesPosition_13; break; case 14: position = notesPosition_14; break; case 15: position = notesPosition_15; break; default: position = new Vector3(0, 0, 0); break; // Error } note.gameObject.transform.position = position; // Add notes.AddLast(new LinkedListNode <NotesScript>(note)); // Add corresponding tapbox GameObject tapboxObject = (GameObject)Instantiate(tapboxPrefab); TapboxScript tapbox = tapboxObject.GetComponent <TapboxScript>(); tapboxObject.transform.position = position; note.tapbox = tapbox; } else { break; } } // Check game done if (notes.Count == 0 && !notesIterator.hasNext()) { common.OnGameOver();; } }
// Setup tapboxes and touch input void SetupTapboxes() { //tapboxes = new List<TapboxScript>(); GameObject sliderObject = (GameObject)Instantiate(tapboxPrefab); slider = sliderObject.GetComponent<TapboxScript>(); exSprite sprite = sliderObject.GetComponent<exSprite>(); sprite.scale = new Vector2(SLIDER_WIDTH, SLIDER_HEIGHT); sprite.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta = sliderPositionInit - sliderPositionEnd; }
// Setup tapboxes and touch input void SetupTapboxes() { //tapboxes = new List<TapboxScript>(); GameObject sliderObject_0 = (GameObject)Instantiate(tapboxPrefab); slider_0 = sliderObject_0.GetComponent<TapboxScript>(); exSprite sprite_0 = sliderObject_0.GetComponent<exSprite>(); sprite_0.scale = sliderSizeInit; sprite_0.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta_0 = sliderPositionInit_0 - sliderPositionEnd_0; GameObject sliderObject_1 = (GameObject)Instantiate(tapboxPrefab); slider_1 = sliderObject_1.GetComponent<TapboxScript>(); exSprite sprite_1 = sliderObject_1.GetComponent<exSprite>(); sprite_1.scale = sliderSizeInit; sprite_1.color = new Color(1, 1, 1, 0.75f); sliderPositionDelta_1 = sliderPositionInit_1 - sliderPositionEnd_1; GameObject sliderObject_2 = (GameObject)Instantiate(tapboxPrefab); slider_2 = sliderObject_2.GetComponent<TapboxScript>(); exSprite sprite_2 = sliderObject_2.GetComponent<exSprite>(); sprite_2.scale = sliderSizeInit; sprite_2.color = new Color(1, 1, 1, 0.75f); sliderObject_2.transform.Rotate(new Vector3(0, 0, 90f)); sliderPositionDelta_2 = sliderPositionInit_2 - sliderPositionEnd_2; GameObject sliderObject_3 = (GameObject)Instantiate(tapboxPrefab); slider_3 = sliderObject_3.GetComponent<TapboxScript>(); exSprite sprite_3 = sliderObject_3.GetComponent<exSprite>(); sprite_3.scale = sliderSizeInit; sprite_3.color = new Color(1, 1, 1, 0.75f); sliderObject_3.transform.Rotate(new Vector3(0, 0, 90f)); sliderPositionDelta_3 = sliderPositionInit_3 - sliderPositionEnd_3; sliderSizeDelta = sliderSizeInit - sliderSizeEnd; }