【发布时间】:2015-04-08 13:26:30
【问题描述】:
我的错误是 Collider2d 是一种类型,但用作变量。 无法修改 transform.position 的返回值,因为它不是变量。 无法将类型 vector2 隐式转换为浮点数。
这是我的代码
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);
}
}
}
}
【问题讨论】:
标签: c# android unity3d touch draggable