我正在制作一些触控按钮而且我收到错误:
错误CS0136:一个名为
ray' cannot be declared in this scope because it would give a different meaning to
ray'的局部变量,已在'父'中使用范围来表示别的东西
代码:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NewBehaviourScript : MonoBehaviour {
public LayerMask TouchInputMask;
private List<GameObject> TouchList = new List<GameObject>();
private GameObject[] TouchesOld;
private RaycastHit2D hit;
void Update () {
#if UNITY_EDITOR
if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) {
TouchesOld = new GameObject[TouchList.Count];
TouchList.CopyTo(TouchesOld);
TouchList.Clear();
}
Ray2D ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit,TouchInputMask)){
gameObject recipient = hit.transform.gameObject;
TouchList.Add(recipient);
if (Input.GetMouseButtonDown(0)) {
recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (Input.GetMouseButtonUp(0)) {
recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (Input.GetMouseButton(0)) {
recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
foreach (GameObject g in TouchesOld) {
if (!TouchList.Contains(g)) {
g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
#endif
if (Input.touchCount > 0) {
TouchesOld = new GameObject[TouchList.Count];
TouchList.CopyTo(TouchesOld);
TouchList.Clear();
}
foreach (Touch touch in Input.touches) {
Ray2D ray = camera.ScreenPointToRay(touch.position);
if (Physics.Raycast(ray, out hit,TouchInputMask)){
gameObject recipient = hit.transform.gameObject;
TouchList.Add(recipient);
if (touch.phase == TouchPhase.Began) {
recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (touch.phase == TouchPhase.Ended) {
recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (touch.phase == TouchPhase.Canceled) {
recipient.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
}
foreach (GameObject g in TouchesOld) {
if (!TouchList.Contains(g)) {
g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
}
}