检测 玩家点击地形位置

2014-3-31 雨辰 Unity3D

/// <summary>
        /// 获取世界位置
        /// </summary>
        /// <returns>The world position.</returns>
        private Vector3 GetWorldPosition()
        {
            Ray ray = camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit raycastHit;
            if (Physics.Raycast(ray, out raycastHit))
            {
                if (raycastHit.collider.gameObject.name == "Terrain")
                {
                    return raycastHit.point;
                }
            }
            return Vector3.zero;
        }

标签: Unity3D

发表评论:

雨辰 joyimp|@2011-2018 京ICP备16030765号