Cześć, mam problem. Napisałem skrypt w C# i działa wszystko co chciałem czyli chodzenie, skakanie i rozglądanie się na boki. Ale jednak nie wiem jak napisać skrypt na rozglądanie pionowe, proszę o pomoc
Skrypt:
using UnityEngine;
public class PlayerController : MonoBehaviour
{
CharacterController cc;
public float WalkSpeed = 6f;
float JumpForce = 0f;
float Gravity = -15f;
public Transform Cam;
float Pitch = 0f;
[Range(1, 10)]
public float Sensitivity = 3f;
void Start()
{
cc = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
float xInput = Input.GetAxis("Horizontal") * WalkSpeed;
float zInput = Input.GetAxis("Vertical") * WalkSpeed;
Vector3 Move = new Vector3(xInput, 0, zInput);
Move = Vector3.ClampMagnitude(Move, WalkSpeed);
Move = transform.TransformVector(Move);
if (cc.isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
JumpForce = 6f;
}
else
{
JumpForce = Gravity * Time.deltaTime;
}
}
else
{
JumpForce += Gravity * Time.deltaTime;
}
cc.Move((Move + new Vector3(0, JumpForce, 0)) * Time.deltaTime);
float xMouse = Input.GetAxis("Mouse X") * Sensitivity;
transform.Rotate(0, xMouse, 0);
Pitch -= Input.GetAxis("Mouse Y") * Sensitivity;
Pitch = Mathf.Clamp(Pitch, -90f, 90f);
Quaternion CamRotation = Quaternion.Euler(Pitch, 0, 0);
Cam.localRotation = CamRotation;
}
}