using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
[HeaderAttribute("CharacterController v3.0")]
[Space]
[SerializeField] private CharacterController Character;
[SerializeField] private Transform Camera;
[Space]
[SerializeReference]
[SerializeField] private float SpeedWalk;
[SerializeField] private float SpeedRun;
[SerializeField] private float JumpForce;
[SerializeField] private float Sensitivity;
[SerializeField] private float Gravity = -9.81f;
[Space]
[SerializeField] private bool MoveMode;
private Vector3 Velocity;
private Vector3 PlayerMovementInput;
private Vector2 PlayerMouseInput;
private float xRot;
void Start()
{
Character = GetComponent<CharacterController>();
}
void Update()
{
//Camera Data
PlayerMouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
//CharacterController Data
PlayerMovementInput = new Vector3(Input.GetAxis("Vertical"), 0f, Input.GetAxis("Horizontal"));
CameraLogic();
}
void FixedUpdate()
{
MovementLogic();
}
private void MovementLogic()
{
Vector3 MoveVector = transform.TransformDirection(PlayerMovementInput);
if (Character.isGrouded) //Подсвечивает .isGround красным как ошибку
{
if(Input.GetKeyDown(KeyCode.Space))
{
Velocity.y = JumpForce;
}
Velocity.y = -1f;
}
else
{
Velocity.y -= Gravity * -2f * Time.deltaTime;
}
Character.Move(MoveVector * SpeedRun * Time.fixedDeltaTime); //Подсвечивает .Move красным как ошибку
Character.Move(Velocity * Time.fixedDeltaTime); //Тоже
}
private void CameraLogic()
{
xRot -= PlayerMouseInput.y * Sensitivity;
transform.Rotate(0f, PlayerMouseInput.x * Sensitivity, 0f);
Character.transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
}
}