BUG NullReferenceException: Object reference not set to an instance of an object
Paddle.Update () (at Assets/Script/Paddle.cs:13)
代码 :
using UnityEngine;
using System.Collections;
public class Paddle : MonoBehaviour {
public float freedom = 19.25f;
// Update is called once per frame
void Update () {
//获取平面与射线相交的点 使托盘随鼠标移动而在X轴移动
if (Input.GetMouseButton(0))
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); // 错误指向这里 鼠标移动托盘不动! 然后有报错
Plane p = new Plane(Vector3.up, transform.position);
float distance;
if (p.Raycast(mouseRay, out distance))
{
Vector3 pos = transform.position;
pos.x = mouseRay.GetPoint(distance).x;
transform.position = pos;
}
}
//限制paddle不要出界
Vector3 temp = transform.position;
if (Mathf.Abs(temp.x) > freedom)
{
temp.x = Mathf.Clamp(transform.position.x, -freedom, freedom);
transform.position = temp;
}
}
}
2015-11-21 14:27
回复 赞(1)共48节 · 42小时54分钟
¥298.0015973人在学
共91节 · 45小时57分钟套餐优惠
¥698.0029531人在学
共14节 · 5小时31分钟套餐优惠
¥98.0019234人在学
共20节 · 10小时7分钟套餐优惠
¥98.0021751人在学