Make me a script that when the e key is pressed at another door, and the player doesn't…
- User
Make me a script that when the e key is pressed at another door, and the player doesn't have the keycard tag in their inventory, using UnityEngine;
public class PlayerInventory : MonoBehaviour { // Singleton instance public static PlayerInventory Instance { get; private set; }
public bool HasKey { get; set; } public bool HasKeycard { get; set; } private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); // Optional: To persist across scenes } else { Destroy(gameObject); } }}
Then make it show text for 1 second that I assign, and make the door not change the scene to "WinScene" if the player does have the Keycard tag in their inventory, the door will work and wil change to "WinScene]"
- Assistant
- User
Using raycast hit
- Assistant
- User
The main camera has the tag main camera
- Assistant
- User
No, make it using text mesh pro, and it will show the text mesh pro text that I assign. Also, don't make me put a tag "Door" on the door, just make it so what the script is attached too.
- Assistant
- User
Not working. The text mesh pro text starts off as hidden, so just enable the text that I assign.
- Assistant
- User
- Assistant
- User
using UnityEngine;
public class PlayerController : MonoBehaviour { public float moveSpeed = 5f; public float lookSensitivity = 2f; public Transform playerCamera; public float gravity = -9.81f;
private CharacterController characterController; private float xRotation = 0f; private Vector3 velocity; void Start() { // Get the CharacterController component attached to the player characterController = GetComponent<CharacterController>(); // Lock the cursor in the center of the screen Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; // Optional: Hide the cursor for gameplay } void Update() { Move(); Look(); ApplyGravity(); } void Move() { float moveX = Input.GetAxis("Horizontal"); float moveZ = Input.GetAxis("Vertical"); Vector3 moveDirection = transform.right * moveX + transform.forward * moveZ; characterController.Move(moveDirection * moveSpeed * Time.deltaTime); } void Look() { float mouseX = Input.GetAxis("Mouse X") * lookSensitivity; float mouseY = Input.GetAxis("Mouse Y") * lookSensitivity; xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, -90f, 90f); playerCamera.localRotation = Quaternion.Euler(xRotation, 0f, 0f); transform.Rotate(Vector3.up * mouseX); // Use transform.Rotate to modify the player's yaw (left/right) movement } void ApplyGravity() { if (characterController.isGrounded && velocity.y < 0) { velocity.y = -2f; // Slightly negative to ensure the controller stays grounded } velocity.y += gravity * Time.deltaTime; characterController.Move(velocity * Time.deltaTime); } - Assistant
- User
It's not working when I walk.
- Assistant
- User
Just make it so it plays whenever I move.
- Assistant
- User
Still not working. Also, make it lock the cursor.
- Assistant