- Home /
Not expecting if on line 17
it says not expecting if on line 17.
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public bool Grounded; public float moveSpeed; public float jumpForce; private Rigidbody2D myRigid;
// Use this for initialization
void Start () {
myRigid = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
if (!Grounded && myRigid.velocity.y == 0)
{
Grounded = true;
}
if (Input.GetMouseButton (0)){
myRigid.velocity = new Vector2(moveSpeed, myRigid.velocity.y);
}
if (Grounded = true && if (Input.GetMouseButtonDown (1)){
myRigid.velocity = new Vector2(myRigid.velocity.x, jumpForce);
Grounded = false;
}
}
Comment
Best Answer
Answer by doublemax · Oct 08, 2016 at 11:45 PM
if (Grounded = true && if (Input.GetMouseButtonDown (1)){
The error even says line 17 and you don't see anything suspicious in this line?
if (Grounded = true && Input.GetMouseButtonDown (1) ){
Also note that Grounded = true is not a check if Grounded is true but it is an assignment to true. This is most likely not intended.
So this line:
if (Grounded = true && Input.Get$$anonymous$$ouseButtonDown (1) ){
would be equivalent to
Grounded = true;
if (Input.Get$$anonymous$$ouseButtonDown (1) ){
So it should be
if (Grounded == true && Input.Get$$anonymous$$ouseButtonDown (1) ){
or simply
if (Grounded && Input.Get$$anonymous$$ouseButtonDown (1) ){
The = operator is the assignment operator while the == operator is a comparison operator for equality.
Your answer