简体   繁体   English

在统一新输入系统中获取触摸位置的问题

[英]Issues in getting Touch Position in unity new input system

I am Making a mobile game , and i am facing some issues in getting touch position properly using new input system in unity .我正在制作一个手机游戏,我在使用新的统一输入系统正确获取触摸位置方面遇到了一些问题。 this is what i am trynig to do .这就是我正在尝试做的。

I want to get the Tap position for a time at which a person holds the screen.我想获得一个人拿着屏幕的时间点的位置。 else the value will be zero否则该值将为零

i am getting the value in screen coordinates, and the values are correct.我正在获取屏幕坐标中的值,并且这些值是正确的。 but when i convert the value using camera.main.screenToWorldPoint() to world coordinates i am getting value of only -16 approx .但是当我使用 camera.main.screenToWorldPoint() 将值转换为世界坐标时,我得到的值只有 -16 左右。 i dont now what is the problem , my screen point values are correct but world point values are -16 only , can some one help me solve this issue我现在不知道有什么问题,我的屏幕点值是正确的,但世界点值只有 -16,有人能帮我解决这个问题吗?

here is my code :----这是我的代码:----

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerInputSystem : MonoBehaviour
{
Controlls controlls;
Controlls.TouchActions TouchControlls;
Controlls.KeyBoardActions KeyBoardControlls;

public FloatRefernce HorizontalAxis; // it is just my custom class


private void Awake()
{
    controlls = new Controlls();
    TouchControlls = controlls.Touch;
    KeyBoardControlls = controlls.KeyBoard;

    TouchControlls.TouchPress.performed += ctx => HorizontalAxis.Value = 
            Camera.main.ScreenToWorldPoint(new Vector3(TouchControlls.TouchPosition.ReadValue<float>() , 0f)).x;

    TouchControlls.TouchPress.canceled += ctx => HorizontalAxis.Value = 0;

}



private void OnEnable()
{
    controlls.Enable();
    TouchControlls.Enable();
    KeyBoardControlls.Enable();
}
 private void OnDisable()
  {
    controlls.Disable();
    TouchControlls.Disable();
    KeyBoardControlls.Disable();
  }
}

Vector3 The worldspace point created by converting the screen space point at the provided distance z from the camera plane Vector3 通过转换屏幕空间点与相机平面提供的距离 z 处创建的世界空间点

Here's a link for you.[https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html]这是给你的链接。[https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html]

So object axis and screentoworldpoint axis are different things.所以对象轴和屏幕到世界点轴是不同的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM