在尝试在这里查找语法错误之前,sql似乎正确地隔开了,并且变量正在从数据库和其他预期的形式读取。
// Adjust this is the Inspector (in Unity units)
public float spawnDistanceToPlayer;
...
// get players position
var playerPos = player.transform.position;
// additionally convert the player position to screen space
var playerScreenPos = Camera.main.WorldToScreenPoint(playerPos);
var centerX = Camera.main.pixelWidth / 2.0f;
// Get the world 3d point for the upper camera border
// with the calculated X value
// and as distance we use the z-distance to the player
var cameraTopPoint = Camera.main.ScreenToWorldPoint(new Vector3(playerScreenPos.x, Camera.main.pixelHeight, playerScreenPos.z);
// now add or reduce spawnDistanceToPlayer
// depending on which side of the screen he is
cameraTopPoint.x += spawnDistanceToPlayer * (playerScreenPos.x < centerX ? 1 : -1);
// OR if your camera sits static on X=0 anyway you also could compare
// the player position directly without calculating in screenspace:
cameraTopPoint.x += spawnDistanceToPlayer * (playerPos.x < 0 ? 1 : -1);
// to spawn it exactly on the Screen border above the player
Instantiate(prefab, cameraTopPoint);
// or to spawn it a bit higher
Instantiate(prefab, cameraTopPoint + Vector3.Up * 1);
答案 0 :(得分:0)
看起来 就像您在同一连接上执行两个嵌套查询一样,但是:通常不支持(除非您启用了“ MARS”,这通常是一个坏主意)。您应该看到一个例外,因为该连接上已经有一个开放的数据读取器。在开始担心其他数据之前,您需要先完成第一个阅读器。您可以通过缓冲数据来做到这一点,但是坦率地说,我怀疑您也可以将查询重新处理为一个具有联接的查询,或者在同一SQL中进行两个查询-这也可能会更多高效(它避免了“ N + 1”)。
另一个主要问题是,您正在连接数据以创建SQL,这总是一个坏主意。在最坏的情况下,这是一个SQL注入漏洞,在最好的情况下,它会使您的查询计划缓存饱和。因此:请使用参数而不是串联。参数还避免了转义,用引号引起来的字符串以及类似如何格式化整数,日期等的i18n / l10n问题。