unity c# 显示与没有结束}相关的错误,但右大括号在那里

问题描述 投票:0回答:0

我对如何缺少花括号和其他东西感到非常困惑 我刚刚开始团结,所以我不太了解。这是代码

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

public class ball_movement : MonoBehaviour
{

    public Rigidbody2D rigidBody;
    public float power = 50;
    public float frictionpower = 10;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {

        if (Input.GetKeyDown(KeyCode.UpArrow) == true){
            rigidBody.AddForce(Vector2.up*power*2);
        }

        if (Input.GetKeyDown(KeyCode.LeftArrow) == true){
            rigidBody.AddForce(Vector2.left*power);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow) == true){
            rigidBody.AddForce(Vector2.right*power);
        }

        AddFriction(frictionpower);
    }

    void AddFriction(float frp)
    {
        private float xcomp = (rigidBody.velocity.x / frp) * -1;
        private float ycomp = (rigidBody.velocity.y / frp) * -1;
        rigidBody.AddForce(new Vector2(xcomp, ycomp));
    }

}

这里是错误代码:-

另外,请告诉我如何在 unity 中正确实施摩擦。我才刚刚开始,所以任何帮助将不胜感激

编辑:- 我开始弄乱代码,发现如果我只输入函数就可以正常工作,但是一旦我取消注释函数中的一行,它就给了我一个错误

c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.