Я делаю игру в Unity, используя зеркало < /p>
В сцене есть две камеры для получения опыта от первого лица и третьего лица, но камера не движется по оси Y . < /p>
using Mirror;
using UnityEngine;
namespace QuickStart
{
public class PlayerScript : NetworkBehaviour
{
public float mouseSensitivity = 100f;
float xRotation = 0f;
// Public variable to access the camera
public Camera playerCamera;
public override void OnStartLocalPlayer()
{
// Assign the main camera to the playerCamera variable
if (Camera.main != null)
{
playerCamera = Camera.main;
playerCamera.transform.SetParent(transform);
playerCamera.transform.localPosition = new Vector3(0, 0, 0);
// Lock the cursor to the center of the screen
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Debug.LogError("Main Camera not found in the scene!");
}
}
void Update()
{
if (!isLocalPlayer) { return; }
// Movement
float moveX = Input.GetAxis("Horizontal") * Time.deltaTime * 110.0f;
float moveZ = Input.GetAxis("Vertical") * Time.deltaTime * 4f;
transform.Rotate(0, moveX, 0);
transform.Translate(0, 0, moveZ);
// Camera Look
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f); // Prevents looking too far up or down
// Use the public camera variable
if (playerCamera != null)
{
playerCamera.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
transform.Rotate(Vector3.up * mouseX);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... not-y-axis
Камера движется по оси x, но не оси Y ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Линия тренда matplotlib с временными метками по оси X, плавает по оси Y
Anonymous » » в форуме Python - 0 Ответы
- 266 Просмотры
-
Последнее сообщение Anonymous
-