using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5f;
public float jumpForce = 7f;
private Rigidbody rb;
private bool isGrounded;
private Vector3 spawnPoint;
void Start()
{
rb = GetComponent<Rigidbody>();
spawnPoint = [Link]; // initial spawn
}
void Update()
{
// Movement
float moveX = [Link]("Horizontal");
float moveZ = [Link]("Vertical");
Vector3 move = [Link] * moveX + [Link] * moveZ;
Vector3 velocity = move * speed;
velocity.y = [Link].y;
[Link] = velocity;
// Jump
if ([Link]([Link]) && isGrounded)
{
[Link]([Link] * jumpForce, [Link]);
}
// Respawn if fall
if ([Link].y < -10f)
{
Respawn();
}
}
private void OnCollisionStay(Collision collision)
{
isGrounded = [Link]("Ground");
}
void Respawn()
{
[Link] = [Link];
[Link] = spawnPoint;
}
}using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public Vector3 offset = new Vector3(0, 5, -7);
public float smoothSpeed = 0.125f;
void LateUpdate()
{
Vector3 desiredPos = [Link] + offset;
Vector3 smoothedPos = [Link]([Link], desiredPos,
smoothSpeed);
[Link] = smoothedPos;
[Link](target);
}
}using UnityEngine;
public class BlockManager : MonoBehaviour
{
public GameObject[] blockPrefabs;
public float placeDistance = 5f;
private int selectedBlock = 0;
void Update()
{
// Inventory scroll
if ([Link].y != 0)
{
selectedBlock = (selectedBlock + (int)[Link].y) %
[Link];
if (selectedBlock < 0) selectedBlock += [Link];
}
// Place block
if ([Link](0))
{
Vector3 placePos = [Link] + [Link] * placeDis -
tance;
Instantiate(blockPrefabs[selectedBlock], placePos, [Link]-
tity);
}
// Rotate block
if ([Link](1)) // Right click
{
Vector3 placePos = [Link] + [Link] * placeDis -
tance;
GameObject block = Instantiate(blockPrefabs[selectedBlock], place-
Pos, [Link]);
[Link](0, 90, 0);
}
// Delete block
if ([Link](KeyCode.E))
{
Ray ray = new Ray([Link], [Link]);
if ([Link](ray, out RaycastHit hit, placeDistance))
{
if ([Link]("Block"))
{
Destroy([Link]);
}
}
}
}
}