我的错误是 Collider2d是一种类型,但像变量一样使用。 无法修改transform.posistion的返回值,因为它不是变量。 无法将类型vector2隐式转换为float。
继承人我的代码
using UnityEngine;
using System.Collections;
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 (Collider2D == Physics2D.OverlapPoint(touchPos))
{
this.transform.position.y = new Vector3 (wp.y,0);
}
}
}
}
答案 0 :(得分:0)
您无法将值设置为position.y / x / z,这是您获得的错误。所以而不是
this.transform.position.y = new Vector3 (wp.y,0);
使用此
this.transform.position = new Vector3 (0,wp.y,0);
如果你想让z和x为零,那么你就明白了。