I’m following Brackeys’ tutorial on making a 3D game in Unity on Youtube and I’m up to the E05 (the collisions video) and I’m trying to make it so when you collide with the obstacle then the player movement is disabled. Here is the code:
Player Movement Code:
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if(Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if(Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
}
Player Collision Code:
public PlayerMovement movement;
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.Enabled = false;
}
}
However when I go back to Unity, the compiler tells me that PlayerMovement contains no definition for .Enabled. I’m sure I followed the video correctly, can anybody help?
>Solution :
You don’t followed video corretly….
You must write enabled in lowercase, Enabled in upper case don’t exit.
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
}
}