android - Unity Android 触摸无法按预期工作

标签 android unity-game-engine unityscript

我使用这个触摸脚本来在触摸屏幕时显示一些效果:

var ParticleA : GameObject;
//var bulletHole : GameObject;

function Update () {

    var hit : RaycastHit;
    // Use Screen.height because many functions (like this one) start in the bottom left of the screen, while MousePosition starts in the top left
    var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);

    if (Input.GetMouseButtonDown(0)) 
    {
        if (Physics.Raycast (ray, hit, 200)) 
        {
            var newparA = Instantiate(ParticleA, hit.point, Quaternion.identity);
            //var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
            //Instantiate(bulletHole, hit.point, hitRotation);
            Destroy(newparA, 12.0);
        }
    }
}

它不适用于 Android。触摸时,它仅在中央屏幕上显示效果,而不是我的手指实际触摸的位置。

问题可能是什么?

最佳答案

您不想使用Input.GetMouseButtonDown(0)(这是针对鼠标的...正如名称所示)。

使用Input.touches:http://docs.unity3d.com/Manual/MobileInput.html

关于android - Unity Android 触摸无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32132354/

相关文章:

android - 我可以使用什么设计模式来完成几个步骤的过程?

java - 在eclipse上创建android项目时出错

android - 使用 PhoneGap/Cordova 为 Android 构建时,在 Mac OS X 10.9 Mavericks 上执行命令 'ant' 时出错

ios - "Different language linkage"— xcode 4 中的警告,xcode 5 中的错误

unity-game-engine - 在unity 5.0.0p2中向刚体添加物理的代码是什么?

android - 旋转或缩放后的 View 中心

unity-game-engine - 使用 Kinect 和 OpenNI 在 Unity 中检测手势

c# - Unity (C#) -> Kotlin <- 协程

c# - Unity 5.4 求物体长度

ios - 在 iPad App 中动态加载 3D 模型