Untitled
user_4957221
plain_text
a year ago
1.0 kB
7
Indexable
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5.0f;
public bool isCreativeMode = false;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
ToggleMode();
}
if (!isCreativeMode)
{
Move();
}
}
void Move()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
}
void ToggleMode()
{
isCreativeMode = !isCreativeMode;
Debug.Log("Mode switched to: " + (isCreativeMode ? "Creative" : "Survival"));
if (isCreativeMode)
{
rb.useGravity = false;
rb.velocity = Vector3.zero;
}
else
{
rb.useGravity = true;
}
}
}Editor is loading...