我是Unity的新手。虽然我正在关注" Catch Game&#34的视频教程;我正在使用Unity 4.3.3版本。
这是我的代码。
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);
}
}
我收到以下错误。
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?)
请更正我的错误。谢谢。
答案 0 :(得分:4)
您需要使用Unity 4.5或更高版本才能使用Rigidbody2D.MovePosition: http://forum.unity3d.com/threads/cannot-figure-out-my-error.253139/
作为解决方法,您可以使用:
rigidbody2D.position = targetPosition;