Tag: raycasting

将3D Raycast转换为Raycast2D

我在下面有这个代码可以控制3个玩家中受影响的玩家。 我能够通过在2D精灵后面添加一个3D立方体来实现它,因为我的游戏应该是2D,我很难在2D中实现它。 我真的很困惑如何在2D中这样做,因为我真的对参数感到困惑。 虽然我已经通过上面提到的方式实现了它,但我仍然希望在纯2D中实现它。 因为当选定的玩家移动时我遇到了这个问题,所以精灵移动得更快。 public GameObject target = null; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.touchCount > 0 || Input.GetTouch(0).phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); Debug.DrawRay(ray.origin,ray.direction * 20,Color.red); RaycastHit hit; if(Physics.Raycast(ray, out hit,Mathf.Infinity)) { Debug.Log(hit.transform.gameObject.name); if(this.target != […]