using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
public bool enableMouse;
[Header("PlayerConfig")]
public string PlayerName;
public int Life;
public float speed;
public float RunSpeed;
public float sensitivity;
[Header("Imports")]
public Camera cam;
//Private
private RigidBody rb;
private float realSpeed;
private Vector3 velocity;
private Vector3 rotation;
private Vector3 camRotation;
private float rotCam;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
#region Movement
float _xMov = Input.GetAxisRaw("Horizontal");
float _yMov = Input.GetAxisRaw("Verical");
if (Input.GetButton("Run") == true && _xMov == 0 && _yMov == 1)
{
realSpeed = RunSpeed;
}
else
{
realSpeed = speed;
}
Vector3 _MoveHorizontal = transform.right * _xMov;
Vector3 _MoveVertical = tranform.forward * _yMov;
velocity = (_MoveHorizontal + _MoveVertical).normalized * realSpeed;
#endregion
#region Rotation
float _yMouse = Input.GetAxisRaw("Mouse x");
rotation = new Vecotr3(0, _yMouse, 0) * sensitivity;
float _xMouse = Input.GetAxisRaw("Mouse y");
camRotation = new Vector3(_xMouse, 0, 0) * sensitivity;
#endregion
#region enableMouse
if (enableMouse)
{
Cursor.lockState = CursorLockMode.Locked;
Curosr.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Curosr.visible = false;
}
#endregion
}
private void FixedUpdate()
{
if (enableMouse == true)
{
Movement();
Rotation();
}
}
void Moviment()
{
if (velocity != Vector3.zero)
rb.MovePosition(rb.position + velocity * Time.deltaTime);
}
void Rotation()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
if (cam != null)
{
rotCam += camRotation.x;
rotCam = Mathf.Clamp(rotCam, -80, 80);
cam.transform.localEulerAngles = new Vector3(-rotCam, 0, 0);
}
}
}
error CS0246: The type or namespace name 'RigidBody' could not be found (are you missing a using dir
“Rigidbody” not “RigidBody”
4 Likes
oh, ok… thanks for the help
y
you found other errors?
Did you?
2 Likes
yea, now i found the errors. that concludes i’m terrible at typing lol
1 Like
lol
You’ve just necro’d a thread for no reason I can understand.
Let’s lock this thread, it’s served its purpose.
3 Likes