Unity3d C#错误:非静态字段、方法或建筑红线12需要对象引用

Unity3d C#错误:非静态字段、方法或建筑红线12需要对象引用,unity3d,Unity3d,您需要从游戏对象中获取刚体组件才能使用它。使用以下命令更改FixeUpdate函数: using UnityEngine; using System.Collections; public class CharacterMovement : MonoBehaviour { public float maxSpeed = 6.0f; public bool FacingRight = true; public float moveDirection; // U

您需要从游戏对象中获取刚体组件才能使用它。使用以下命令更改FixeUpdate函数:

using UnityEngine;
using System.Collections;

public class CharacterMovement : MonoBehaviour {
    public float maxSpeed = 6.0f;
    public  bool FacingRight = true;
    public float moveDirection;

    // Use this for initialization
    void FixedUpdate () {
        Rigidbody.velocity=newVector2(moveDirection*maxSpeed,Rigidbody.velocity.y);
     /**the error is in this line this is a simple game where the player just move left and right
        where when the D +ve number  is clicked the player moves forward (right) **/
    }

    // Update is called once per frame
    void Update () {
        moveDirection = Input.GetAxis("Horizontal");
    }
}
void FixedUpdate()
{ 
刚体刚体=gameObject.GetComponent();
rigidbody.velocity=新矢量2(移动方向*最大速度,rigidbody.velocity.y);
}
gameObject.GetComponent().velocity=newvector2(moveDirection*maxSpeed,GetComponent().velocity.y);谢谢你帮了我谢谢我知道还是初学者它是这样工作的
 void FixedUpdate () 
 { 
      RigidBody rigidbody = gameObject.GetComponent<RigidBody>();
      rigidbody.velocity = new Vector2(moveDirection*maxSpeed,rigidbody.velocity.y);
 }