【发布时间】:2021-09-14 14:34:55
【问题描述】:
我是 Unity 和 C# 的新手,我想使用“AddForce”对 3D 对象(球体)施加力。我尝试在 Visual Studio 2019(使用 Unity 2020.2.0b14)中运行以下 C# 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Script14sept : MonoBehaviour {
public float forceValue;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponentInParent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
rb.AddForce(new Vector3(Input.GetAxis("Horizontal"),
0,
Input.GetAxis("Vertical")) * forceValue);
}
}
但是,运行此代码会导致错误: 错误 CS0122 'Rigidbody.AddForce(Vector3)' 由于其保护级别而无法访问
代码有问题还是取决于其他问题(例如,使用 Unity 的 beta 版本)?
【问题讨论】:
-
但是,这是我第一次看到...怀疑这是针对其中一个 beta 版本进行了更改,然后突然又起作用了^^奇怪的事情...
标签: c# visual-studio unity3d