unity3d - 从 ScreenToWorldPoint 转换给我错误的值
问题描述
GameObjects
我使用以下代码通过脚本实例化一些:
for (int x = 0; x < data.game.Length; x++)
for (int y = 0; y < data.game[x].LayerList.Length; y++)
{
int posX = data.game[x].LayerList[y].PositionOnMapX;
int posY = data.game[x].LayerList[y].PositionOnMapY;
InsertWord(data.game[x].LayerList[y].Word, data.game[x].LayerList[y].Direction, posX, posY, boardHeight);
}
}
和
private void InsertWord(string word, int direction, int positionX, int positionY, int boardHeight)
{
int x = positionX;
int y = boardHeight - positionY;
for (int i = 0; i < word.Length; i++)
{
string letter = word.Substring(i, 1);
tileText.text = letter;
Vector2 tempPosition = new Vector2(x, y);
/// Instantiate Background Tile
GameObject backgroundTile = Instantiate(tilePrefab, tempPosition, Quaternion.identity, this.transform) as GameObject;
backgroundTile.name = letter + " ( " + x + "," + y + ")";
allTiles[x, y] = backgroundTile;
if (direction == 0)
x += 1;
else
y -= 1;
}
}
对象已正确实例化。问题是它们是在屏幕视图坐标中实例化的,但我需要将它们转换为世界点,因为它们不在屏幕上。
我试图转换tempPosition
为 WorldCoordinates:
Vector3 screenVector = camera.ScreenToWorldPoint(new Vector3(x,y,10))
但所有实例化GameObjects
的 X,Y,Z (2.3 , 5, 0) 都相同。
解决方案
推荐阅读
- apache - 盗链保护 - 讨论
- asp.net-core - Asp.net Core Web Api 中的响应包装器
- python - 弹跳 2D 球 - Python
- python - Python中的数组TP,TN,FP和FN
- python - 我无法使用 docker-compose 对 MySQL 和 Django App 进行 Dockerize
- spring - 会话范围 CacheManager 不能在 @Cacheable 中使用。如何解决?
- node.js - 重新安装节点和 npm 后打字稿代码库失败
- javascript - 获取 Firestore 抛出未安装警告的文档方法
- javascript - 根据您的经验,React 的最佳 UI 框架(例如 Material UI 或其他)?
- graphql - 如何将 GraphqlSchema 转换为联合模式?