【发布时间】:2018-02-15 00:39:06
【问题描述】:
不确定是否可以将 Ray 用于统一的游戏对象,鼠标单击是可能的,但如果游戏对象不可能复制结果?
需要以下代码以相同的方式工作,让光线进入玩家的位置,而不是鼠标点击。
// Get the place the player has clicked
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Holds information regarding the mouseclick
RaycastHit hitInfo;
// Now work out if we fire or not
if (Physics.Raycast(ray, out hitInfo))
{
if(hitInfo.distance < maxRange)
{
FireAtPoint(hitInfo.point);
尝试执行以下操作,尽管它没有给出正确的位置,而是在播放器静止时给出了不同的位置。
// Holds information regarding the mouseclick
RaycastHit hitInfo;
// Now work out if we fire or not
if (Physics.Raycast(player.transform.position,transform.forward, out hitInfo))
{
【问题讨论】:
-
让我猜猜:你的游戏不是第一人称视角。
-
不是它不是 :) 抛物线射击和其他东西变得更有趣,这是试图为敌人 AI @Draco18s 替换射线的问题
标签: c# unity3d game-physics raycasting