Code Cleanup: tetromino audio source

This commit is contained in:
Kaj Forney 2022-10-07 14:47:24 -06:00
parent 15e5bb8c04
commit abe59f86b1
Signed by: kforney
GPG key ID: 3AB4E2E04CEF656F

View file

@ -4,8 +4,14 @@ using UnityEngine.SceneManagement;
public class tetrominoUserControl : MonoBehaviour
{
public GameObject activeTetromino;
private AudioSource audioSource;
// Update is called once per frame
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetButtonDown("tetrisMoveLeft") && activeTetromino != null)
@ -13,7 +19,7 @@ public class tetrominoUserControl : MonoBehaviour
if (!checkMoveCollisions(Vector2.left))
{
activeTetromino.gameObject.transform.position += Vector3.left * 1.0f;
GetComponent<AudioSource>().Play();
audioSource.Play();
}
}
@ -22,7 +28,7 @@ public class tetrominoUserControl : MonoBehaviour
if (!checkMoveCollisions(Vector2.right))
{
activeTetromino.gameObject.transform.position += Vector3.right * 1.0f;
GetComponent<AudioSource>().Play();
audioSource.Play();
}
}
@ -31,20 +37,20 @@ public class tetrominoUserControl : MonoBehaviour
if (!checkMoveCollisions(Vector2.down))
{
activeTetromino.gameObject.transform.position += Vector3.down * 1.0f;
GetComponent<AudioSource>().Play();
audioSource.Play();
}
}
if (Input.GetButtonDown("tetrisRotateLeft") && activeTetromino != null)
{
checkRotateCollisions(90);
GetComponent<AudioSource>().Play();
audioSource.Play();
}
if (Input.GetButtonDown("tetrisRotateRight") && activeTetromino != null)
{
checkRotateCollisions(90);
GetComponent<AudioSource>().Play();
audioSource.Play();
}
if (Input.GetButtonDown("Quit"))