请查看以下图片:
第二张图片是我在Android设备上运行代码时的效果。
以下是附加到Play Game(它是一段3D文本)的代码。
第二张图片是我在Android设备上运行代码时的效果。
以下是附加到Play Game(它是一段3D文本)的代码。
using UnityEngine;
using System.Collections;
public class PlayButton : MonoBehaviour {
public string levelToLoad;
public AudioClip soundhover ;
public AudioClip beep;
public bool QuitButton;
public Transform mButton;
BoxCollider boxCollider;
void Start () {
boxCollider = mButton.collider as BoxCollider;
}
void Update () {
foreach (Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
if (boxCollider.bounds.Contains (touch.position)) {
Application.LoadLevel (levelToLoad);
}
}
}
}
}
我希望确定触摸点是否在碰撞器内。我想这样做是因为当前情况是,如果我在场景上点击任何位置,则调用Application.LoadLevel(levelToLoad)。
我希望只有当我点击PLAY GAME文本时才调用它。有人能帮我修复这段代码或提供另一种解决方案吗?
根据Heisenbug的逻辑进行的最近代码
void Update () {
foreach( Touch touch in Input.touches ) {
if( touch.phase == TouchPhase.Began ) {
Ray ray = camera.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, 10)) {
Application.LoadLevel(levelToLoad);
}
}
}
}