Hello, I have a problem:
I have a BlockMovement with which you can move blocks with left arrow / right arrow, left or right.
The BlockMovement is on the prefabs of all blocks.
Well, if a block fell down. A new one spawns.
But now I can move both blocks.
And then three, four, etc.
How do I fix that only the newly spawned block moves or the block that has already fallen is “fixed” in its position?
using UnityEngine;
public class BlockMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.position = new Vector3(transform.position.x + 1,
transform.position.y,
transform.position.z);
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.position = new Vector3(transform.position.x - 1,
transform.position.y,
transform.position.z);
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Block") || collision.gameObject.CompareTag("Ground"))
{
this.enabled = false;
}
}
}