我是 unity 的新手,并试图让玩家在开始时跳跃。 我有以下代码
using System.Collections;
using UnityEngine;
public class playermove : MonoBehaviour
{
public float Force = 20f;
// Start is called before the first frame update
void Start()
{
Rigidbody.AddForce(0f, 0f, 200f);
}
// Update is called once per frame
void Update()
{
}
}
它向我抛出以下错误
Assets\playermove.cs(10,9): error CS0120: An object reference is required for the non-static field, method, or property 'Rigidbody.AddForce(float, float, float)'
答案 0 :(得分:0)
你需要一个 Rigidbody 类的实例
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class playermove : MonoBehaviour
{
public Rigidbody rb;
public float Force = 20f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
rb.AddForce(0f, 0f, Force);
}
// Update is called once per frame
void Update()
{
}
}