简体   繁体   English

在Unity中找不到刚性主体2D.MovePosition

[英]rigidBody2D.MovePosition not found in Unity

I am new to Unity.While i am following the video tutorial of "Catch Game".. I am using the unity 4.3.3 version. 我是Unity的新手,而我正在关注“ Catch Game”的视频教程。.我使用的是Unity 4.3.3版本。

here is my code. 这是我的代码。

using UnityEngine;
using System.Collections;

public class BasketController : MonoBehaviour {

    public Camera cam;
    // Use this for initialization
    void Start () {
        if (cam == null) 
        {
            cam = Camera.main;      
        }
    }

    // Update is called once physics TimeStep  
    void FixedUpdate () {
        Vector3 rawPosition = cam.ScreenToWorldPoint (Input.mousePosition);
        Vector3 targetPosition = new Vector3 (rawPosition.x, 0.0f, 0.0f);
        rigidbody2D.MovePosition (targetPosition);
    }
}

I am getting the following error. 我收到以下错误。

error CS1061: Type `UnityEngine.Rigidbody2D' does not contain a definition for `MovePosition' and no extension method `MovePosition' of type `UnityEngine.Rigidbody2D' could be found (are you missing a using directive or an assembly reference?)

Kindly correct my error.Thanks in advance.. 请更正我的错误。谢谢。

You need to have Unity 4.5 or newer to use Rigidbody2D.MovePosition: http://forum.unity3d.com/threads/cannot-figure-out-my-error.253139/ 您需要拥有Unity 4.5或更高版本才能使用Rigidbody2D.MovePosition: http : //forum.unity3d.com/threads/cannot-figure-out-my-error.253139/

As workaround you could probably use: 作为解决方法,您可以使用:

rigidbody2D.position = targetPosition;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM