gimm-platformer-project/Assets/Scripts/tetrominoUserControl.cs

58 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tetrominoUserControl : MonoBehaviour
{
public GameObject activeTetromino;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("tetrisMoveLeft") && activeTetromino != null)
{
activeTetromino.gameObject.transform.position += Vector3.left * 1.0f;
GetComponent<AudioSource>().Play();
}
if (Input.GetButtonDown("tetrisMoveRight") && activeTetromino != null)
{
activeTetromino.gameObject.transform.position += Vector3.right * 1.0f;
GetComponent<AudioSource>().Play();
}
if (Input.GetButtonDown("tetrisDrop") && activeTetromino != null)
{
activeTetromino.gameObject.transform.position += Vector3.down * 1.0f;
GetComponent<AudioSource>().Play();
}
if (Input.GetButtonDown("tetrisRotateLeft") && activeTetromino != null)
{
activeTetromino.gameObject.transform.Rotate(0,0,90,Space.World);
GetComponent<AudioSource>().Play();
}
if (Input.GetButtonDown("tetrisRotateRight") && activeTetromino != null)
{
activeTetromino.gameObject.transform.Rotate(0,0,-90,Space.World);
GetComponent<AudioSource>().Play();
}
}
public void setActiveTetromino(GameObject tetromino)
{
activeTetromino = tetromino;
}
public void unsetActiveTetromino()
{
activeTetromino = null;
}
}