我的错误是
发布于 2015-04-08 22:23:15
你这里有两个问题。首先,您试图将Collider2D结果Physics2D.OverlapPoint(touchPos)分配给Touch的统一结构类型。不太清楚你的意图是什么。如果您只想测试touchPos是否重叠,请使用以下代码:
public class MoveRacket : MonoBehaviour {
public float speed = 30;
public string axis = "Vertical";
public object racket = "Racket";
public bool touchInput = true;
public Vector2 touchPos;
void FixedUpdate () {
//used to not have anything in parentheses
//float v = Input.GetAxisRaw (axis);
float v = Input.GetAxisRaw (axis);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * speed;
if (Input.touchCount == 1)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (Physics2D.OverlapPoint(touchPos) != null)
{
this.transform.position = new Vector3 (3.94f,wp.y,0);
}
}
}
}另一个问题是,当vector3构造函数期望浮动时,值3.94被视为一个双数据类型。若要将其解释为浮点数,请在数字的末尾添加"f“。
https://stackoverflow.com/questions/29525713
复制相似问题