Search Unity

The Left-hand of an assignment must be a variable, property or an indexer.

Discussion in 'Scripting' started by mateor861, Jun 20, 2018.

  1. mateor861

    mateor861

    Joined:
    Jun 20, 2018
    Posts:
    3
    Hola!
    Tengo un problema en mi script y es el siguiente:


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Bird : MonoBehaviour {


    private bool isDead;
    public Rigidbody2D rb2d;
    public float upForce;



    private void Update () {
    if (isDead) return;
    if (Input.GetMouseButtonDown(0)){
    rb2d.velocity = Vector2.zero;
    rb2d.AddForce = (new Vector2(0, upForce));
    }

    }
    private void OnCollisionEnter2D(Collision2D collision){
    isDead = true;
    }


    }


    Me marca esa linea con el problema "The Left-hand of an assignment must be a variable, property or an indexer."
    ¿Alguien puede ayudarme? Se lo agradeceria muchisimo, gracias de antemano.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    Use code tags. The forum also speaks English.

    By using
    rb2d.AddForce = (new Vector2(0, upForce));
    you're saying that AddForce will EQUALS this new thing, which makes absolutely no sense because it is not a variable field that you can define or assign in that way.

    Instead, understand that AddForce is a METHOD and you need to call it and pass in your force as an argument.

    rb2d.AddForce(new Vector2(0, upForce));
     
    mateor861 likes this.
  3. mateor861

    mateor861

    Joined:
    Jun 20, 2018
    Posts:
    3
    Thank you so much!!! you are my hero xdxd