please can someone help it shows only assignment,cal

时间:2019-04-08 13:41:03

标签: c#

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

public class movingplayer1 : MonoBehaviour
{
    private Rigidbody2D reg;
    public float speed = 10f;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update(){
        var Newx = 0f;
        var Newy = 0f;
        reg = GetComponent<Rigidbody2D> ();
        if(Input.GetKey("right")){
         Newx+speed;    

           }
           else if(Input.GetKey("left")){
                Newx-speed;   
                   }
           reg.AddForce (new vector2 (Newx,Newy));

    }
}

im new in oop and i need some help guys it shows only assignment call increment decrement await and new object expressions can be used as a statement.

1 个答案:

答案 0 :(得分:1)

Issues are

Newx+speed;
Newx-speed;

You should assign the result. They should be

Newx += speed;
Newx -= speed;

or

Newx = Newx + speed;
Newx = Newx - speed;
相关问题