Home > database >  i want to add player input in unity but i am getting an error message
i want to add player input in unity but i am getting an error message

Time:09-16

error CS1026: ) expected is my error message this is my code

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

    // This is a reference to the Rigidbody component called "rb"
    public Rigidbody rb;

    public float forwardforce = 2000f ;


    // We marked this as fixedUpdate because we
    // are using it to mess with physics.
    void FixedUpdate ()
    {
        rb.AddForce(0, 0, forwardforce * Time.deltaTime);   // Add a force of 2000 on the z-axis

        if (Input.Getkey("d")

            (
                rb.Addforce(500*Time.deltatime, 0, 0);
            )
    }
}

CodePudding user response:

As per comment above - your if statement should look like this:

if (Input.Getkey("d"))

{
      rb.Addforce(500*Time.deltatime, 0, 0);
}

Usually an IDE should point it out for you.

CodePudding user response:

You made a mistake right here:

if (Input.Getkey("d")

        (
            rb.Addforce(500*Time.deltatime, 0, 0);
        )

You used (), instead of {}. There is a simple solution:

Use after the statement {}

.

if (Input.Getkey("d")

        {
            rb.Addforce(500*Time.deltatime, 0, 0);
        }
  • Related