Skip to content

jogador #54

@Jomano99

Description

@Jomano99

using UnityEngine;

public class PlayerController : MonoBehaviour
{
public float speed = 5f; // Velocidade do jogador

void Start()
{
    // Esconde e trava o cursor
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
}

void Update()
{
    // Movimento do jogador
    float moveX = Input.GetAxis("Horizontal"); // A/D ou ← →
    float moveZ = Input.GetAxis("Vertical");   // W/S ou ↑ ↓

    Vector3 move = transform.right * moveX + transform.forward * moveZ;
    transform.position += move * speed * Time.deltaTime;

    // Alternar cursor com ESC
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (Cursor.lockState == CursorLockMode.Locked)
        {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
        }
        else
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible = false;
        }
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions