So, im creating a fps game. I got a code for controlling player movement and
the type or namespace name [hideininspector] show up in unity after i edit the playermovement.cs
how to fix
using UnityEngine;
using System. Collections;
public class PlayerMovement : MonoBehaviour {
public GameObject cameraObject;
public float acceleration ;
public float walkAccelerationRatio ;
public float maxWalkSpeed ;
public float deaccelerate = 2;
[Hidelnlnspector]
public Vector2 horizontalMovement;
[Hidelnlnspector]
public float walkDeaccelerateX;
[Hidelnlnspector]
public float walkDeaccelerateZ;
[Hidelnlnspector]
public bool isGrounded = true;
Rigidbody playerRigidBody;
public float jumpVelocity = 20;
float maxSlope = 45;
void Awake()
{
// [Getting the rigidbody component from player
playerRigidBody = GetComponent();
}
void Update ( )
{ Jump();
Move();
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
playerRigidBody.Addforce(0, jumpVelocity, 0);
}
}
void Move() {
//Controlling the limit of player by measuring the Vector 3 magnitude and then measuring and normalizing that vector
horizontalMovement = new Vector2(playerRigidBody. velocity.x, playerRigidBody. velocity. z);
if (horizontalMovement.magnitude > maxWalkSpeed)
{
horizontalMovement = horizontalMovement. normalized;
horizontalMovement *= maxWalkSpeed;
}
playerRigidBody.velocity = new Vector3(horizontalMovement.x, playerRigidBody.velocity.y,
horizontalMovement.y); //Controlling only X and Z speed of the cube movement
//Rotating the player capsule according to MouseLook current Y variable so that player looks exaclty where camera is looking .
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent() , currentY, 0);
//Moving here
if(isGrounded) //Complete control while player is on the ground
playerRigidBody.AddRelativeForce(Input.GetAxis(“Horizontal”) * acceleration, 0,
Input.GetAxis(“Vertical”) * acceleration);
else// [Complete control while player is in the air
playerRigidBody.AddRelativeForce(Input.GetAxis(“Horizontal”) * acceleration *
walkAccelerationRatio, 0, Input.GetAxis( “Vertical”) * walkAccelerationRatio
- acceleration);
if (isGrounded) // This section of code adds friction to player’s movement so that it doesnot slips when no force is aDDlied
{float xMove = Mathf.SmoothDamp(playerRigidBody. velocity.x, 0, ref walkDeaccelerateX, deaccelerate);
float zMove = Mathf.SmoothDamp(playerRigidBody. velocity. z, 0, ref walkDeaccelerateZ, deaccelerate);
playerRigidBody.velocity = new Vector3(xMove, playerRigidBody. velocity. y, zMove);
}
}
// this builtin method gets called whenever unity detects collision of two bodies
void OnCollisionEnter(Collision coll) {
foreach (ContactPoint contact in coll. contacts)
{
if (Vector3.Angle(contact. normal, Vector3.up) < maxSlope)//detecting
isGrounded = true;
}
}
//[Making player state in the air
void OnCollisionExit(Collision coll)
{
if (coll.gameObject.name.Equals (“Plane”)) {
isGrounded = false;
}
}
}