0

I am making a 2D piano player game. I am mostly done, but I am new to Unity and programming in C#, and I am not sure how to do the next part. What do I do to make it so that when I press the record button, it records the notes and then plays it back when the play button is pressed? My script is down below. Thank you in advance for your help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NotePlay : MonoBehaviour {
    Animator anim;
    public AudioClip noteA;
    public AudioClip noteB;
    public AudioClip noteC;
    public AudioClip noteD;
    public AudioClip noteE;
    public AudioClip noteF;
    public AudioClip noteG;
    public AudioSource audio;
    public string[] store;
    private KeyCode lastHitKey;

    // Use this for initialization
    void Start() {
        anim = gameObject.GetComponent<Animator>();
        audio = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update() {
        if (Input.GetKeyDown(KeyCode.A)) {
            anim.SetTrigger("A");
            audio.PlayOneShot(noteA);
        }
        if (Input.GetKeyDown(KeyCode.B)) {
            anim.SetTrigger("B");
            audio.PlayOneShot(noteB); 
        }
        if (Input.GetKeyDown(KeyCode.C)) {
            audio.PlayOneShot(noteC);
            anim.SetTrigger("C");
        }
        else if (Input.GetKeyDown(KeyCode.D)) {
            anim.SetTrigger("D");
            audio.PlayOneShot(noteD);
        }
        else if (Input.GetKeyDown(KeyCode.E)) {
            anim.SetTrigger("E");
            audio.PlayOneShot(noteE);
        }
        if (Input.GetKeyDown(KeyCode.F)) {
            anim.SetTrigger("F");
            audio.PlayOneShot(noteF);
        }
        if (Input.GetKeyDown(KeyCode.G)) {
            anim.SetTrigger("G");
            audio.PlayOneShot(noteG);
        }
    }
}
pushkin
  • 9,575
  • 15
  • 51
  • 95
deep
  • 11
  • 4
  • A bit far fetched what you asking. You new to programming so saying you should write a json file with the note, the time it was hit and the length of the press...you are going to ask what is json and how to fill it. – Everts May 06 '18 at 18:13
  • i was thinking more of taking key presses and putting them in an array, then inputting the array into the program to play notes, i can do the first part in java using scanner but i dont know how to do it in C#, if that doesn't work then ill research json – deep May 07 '18 at 01:00
  • oh ok. that is a bit simpler. – Everts May 07 '18 at 04:27

0 Answers0