Change button after 'x' amount of time

So sorry but that still doesnt work for some reason, I’ll show you all of the code for the gameobject! thanks so much for the help!!

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

public class TetrisObject : MonoBehaviour
{

float lastFall = 0f;

// Use this for initialization
void Start()
{

}

// Update is called once per frame
void Update()
{

    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        transform.position += new Vector3(-1, 0, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(1, 0, 0);
        }

    }
    else if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        transform.position += new Vector3(1, 0, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(-1, 0, 0);
        }
    }
    else if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        transform.Rotate(new Vector3(0, 0, -90));

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.Rotate(new Vector3(0, 0, 90));
        }
    }
    else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - lastFall >= 1)
    {
        transform.position += new Vector3(0, -1, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(0, 1, 0);

            MatrixGrid.DeleteWholeRows();

            FindObjectOfType<Spawner>().SpawnRandom();

            enabled = false;
        }
        lastFall = Time.time;

    }

}

bool IsValidGridPosition()
{
    foreach (Transform child in transform)
    {
        Vector2 v = MatrixGrid.RoundVector(child.position);

        if (!MatrixGrid.IsInsideBorder(v))
            return false;

        if (MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v.y].parent != transform)
            return false;

    }
    return true;
}

void UpdateMatrixGrid()
{
    for (int y = 0; y < MatrixGrid.column; ++y)
    {
        for (int x = 0; x < MatrixGrid.row; ++x)
        {
            if (MatrixGrid.grid[x, y] != null)
            {
                if (MatrixGrid.grid[x, y].parent == transform)
                {
                    MatrixGrid.grid[x, y] = null;
                }
            }
        }
    }

    foreach (Transform child in transform)
    {
        Vector2 v = MatrixGrid.RoundVector(child.position);
        MatrixGrid.grid[(int)v.x, (int)v.y] = child;
    }
}

} //tetrisobject

@Vega4Life

Here is a simple example of using a delegate.


using UnityEngine;


public class InputChanger : MonoBehaviour
{
    float timer = 60f;
    float elapsedTime = 0f;

    delegate void ThingToDo();
    ThingToDo leftInput;
    ThingToDo rightInput;


    void Awake()
    {
        leftInput = MoveLeft;
        rightInput = MoveRight;
    }


    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Debug.Log("Left Button Pressed");
            leftInput();
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            Debug.Log("Right Button Pressed");
            rightInput();
        }


        elapsedTime += Time.deltaTime;
        if (elapsedTime >= timer)
        {
            elapsedTime = 0f;

            ThingToDo container = leftInput;
            leftInput = rightInput;
            rightInput = container;

            Debug.Log("Switch");
        }
    }


    void MoveLeft()
    {
        Debug.Log("Moving Left");
    }


    void MoveRight()
    {
        Debug.Log("Moving Right");
    }
}

The idea is the keys aren’t changing, just the content it goes to does. Hitting left arrow, will say “Left Button Pressed” and “Moving Left”. After it switches it will say “Left Button Pressed” and “Moving Right”


Hope it helps, good luck!


@Vega4Life thanks! is there a way i need to link it to the game? Doesn’t seem to be working! thanks again!

The game is tetris, i currently have this in the update section of my GameObject

void Update()
{

    if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        transform.position += new Vector3(-1, 0, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(1, 0, 0);
        }

    }
    else if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        transform.position += new Vector3(1, 0, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(-1, 0, 0);
        }
    }
    else if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        transform.Rotate(new Vector3(0, 0, -90));

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.Rotate(new Vector3(0, 0, 90));
        }
    }
    else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - lastFall >= 1)
    {
        transform.position += new Vector3(0, -1, 0);

        if (IsValidGridPosition())
        {
            UpdateMatrixGrid();
        }
        else
        {
            transform.position += new Vector3(0, 1, 0);

            MatrixGrid.DeleteWholeRows();

            FindObjectOfType<Spawner>().SpawnRandom();

            enabled = false;
        }
        lastFall = Time.time;

    }

}

but do not know where to put your code!