我有2个gui纹理。在GUI纹理上检测触摸
根据屏幕宽度和高度,我把它放在gui中。
一个用于操纵杆,另一个用于射手。
现在触摸射手游戏杆移动到该特定部分。
我用rect.Contains。
void Start() {
xx = Screen.width - Screen.width/12;
yy = Screen.height - Screen.height/8;
lb = Screen.width/10;
rect = new Rect(-xx/2, -yy/2, lb, lb);
shooter.pixelInset = rect;
shooter.enabled = false;
}
void OnGUI(){
if(characterScript.playbool){
shooter.enabled = true;
}
if (rect.Contains(Event.current.mousePosition)){
shootBool = true;
print("shoot");
alert.text="shoot";
}
}
对我来说工作不正常。认为空间坐标不同于gui坐标。如何解决这个问题。任何人都可以建议其他好方法
获取错误错误CS1061:类型'UnityEngine.Rect'不包含'HitTest'的定义,并且没有找到'UnityEngine.Rect'类型的扩展方法'HitTest'(你是否缺少using指令或程序集参考?) – Sona 2013-03-18 10:14:39
哦,原谅我,只适用于GUI元素。你可以试试'rect.Contains(touch.position)'! – Joetjah 2013-03-18 10:33:19
我编辑了我的答案以反映这一点。 – Joetjah 2013-03-18 10:33:43