- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的“Update()”函数中有一段代码,用于获取场景中的事件 block ,当它找到该 block 时,它会将这些坐标传递给“generateFromMiddleOfChunk()”函数。该函数将生成玩家周围 3 半径范围内的所有 block ,它使用 25 个“Instantiate()”函数和一个公式来实现。但它只应该在还没有 block 的地方实例化 block 。它不会那样做,如果有人可以看一下我的代码,我将不胜感激。对于非常重复的代码和大量 Debug.Log()
函数,我深表歉意。非常感谢您的帮助,非常感谢。
乔迪,
我的 Update()
函数中有这段代码:
function Update() {
var gameObjects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
for (var i = 0; i < gameObjects.length ; i++) {
if(gameObjects[i].name.Substring(0,6) == "ACTIVE")
if(gameObjects[i].tag != "Player") {
var xco = gameObjects[i].transform.position.x;
var yco = gameObjects[i].transform.position.y;
var zco = gameObjects[i].transform.position.z;
Debug.Log(xco.ToString()+yco.ToString()+zco.ToString());
generateFromMiddleOfChunk(xco, yco, zco);
}
}
}
此代码块获取场景中的 block 并获取其 x、y 和 z 坐标,并将这些坐标传递给 generateFromMiddleOfChunk()
函数。这个函数看起来像这样:
function generateFromMiddleOfChunk(xco : int, yco : int, zco : int) {
//V1
chunk1 = "Chunk (" + xco.ToString() + ", " + yco.ToString() + ", " + zco.ToString() + ")";
chunk2 = "Chunk (" + (xco + chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco+chunkWidth).ToString() + ")";
chunk3 = "Chunk (" + (xco + chunkWidth).ToString() + ", " + yco.ToString() + ", " + zco.ToString() + ")";
chunk4 = "Chunk (" + (xco + chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco * -1).ToString() + ")";
chunk5 = "Chunk (" + (xco + chunkWidth * -1).ToString() + ", " + yco.ToString() + ", " + (zco+chunkWidth).ToString() + ")";
chunk6 = "Chunk (" + (xco + chunkWidth * -1).ToString() + ", " + yco.ToString() + ", " + zco.ToString() + ")";
chunk7 = "Chunk (" + (xco + chunkWidth * -1).ToString() + ", " + yco.ToString() + ", " + (zco * -1).ToString() + ")";
chunk8 = "Chunk (" + xco.ToString() + ", " + yco.ToString() + ", " + (zco + chunkWidth).ToString() + ")";
chunk9 = "Chunk (" + xco.ToString() + ", " + yco.ToString() + ", " + (zco * -1).ToString() + ")";
chunk10= "Chunk (" + (xco + chunkWidth * -2).ToString() + ", " + yco.ToString() + ", " + (zco + 2 * chunkWidth).ToString() + ")";
chunk11= "Chunk (" + (xco + chunkWidth * -2).ToString() + ", " + yco.ToString() + ", " + (zco + chunkWidth).ToString() + ")";
chunk12= "Chunk (" + (xco + chunkWidth * -2).ToString() + ", " + yco.ToString() + ", " + zco.ToString() + ")";
chunk13= "Chunk (" + (xco + chunkWidth * -2).ToString() + ", " + yco.ToString() + ", " + (zco * -1).ToString() + ")";
chunk14= "Chunk (" + (xco + chunkWidth * -2).ToString() + ", " + yco.ToString() + ", " + (zco + -2 * chunkWidth).ToString() + ")";
chunk15= "Chunk (" + (xco + chunkWidth * -1).ToString() + ", " + yco.ToString() + ", " + (zco + 2 * chunkWidth).ToString() + ")";
chunk16= "Chunk (" + (xco + chunkWidth * -1).ToString() + ", " + yco.ToString() + ", " + (zco + -2 * chunkWidth).ToString() + ")";
chunk17= "Chunk (" + xco.ToString() + ", " + yco.ToString() + ", " + (zco + 2 * chunkWidth).ToString() + ")";
chunk18= "Chunk (" + xco.ToString() + ", " + yco.ToString() + ", " + (zco + -2 * chunkWidth).ToString() + ")";
chunk19= "Chunk (" + (xco + chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco + 2 * chunkWidth).ToString() + ")";
chunk20= "Chunk (" + (xco + chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco + -2 * chunkWidth).ToString() + ")";
chunk21= "Chunk (" + (xco + 2 * chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco + 2 * chunkWidth).ToString() + ")";
chunk22= "Chunk (" + (xco + 2 * chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco + chunkWidth).ToString() + ")";
chunk23= "Chunk (" + (xco + 2 * chunkWidth).ToString() + ", " + yco.ToString() + ", " + zco.ToString() + ")";
chunk24= "Chunk (" + (xco + 2 * chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco * -1).ToString() + ")";
chunk25= "Chunk (" + (xco + 2 * chunkWidth).ToString() + ", " + yco.ToString() + ", " + (zco + -2 * chunkWidth).ToString() + ")";
var chunksInScene : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
for (var i = 0; i < chunksInScene.length ; i++) {
if(chunksInScene[i].name.Substring(0,5) == "Chunk" || chunksInScene[i].name.Substring(0,5) == "_TERR" || chunksInScene[i].name.Substring(0,5) == "ACTIV") {
if(chunksInScene[i].tag != "Player") {
var oldXco = chunksInScene[i].transform.position.x;
var oldYco = chunksInScene[i].transform.position.y;
var oldZco = chunksInScene[i].transform.position.z;
oldChunk1 = "Chunk (" + oldXco.ToString() + ", " + oldYco.ToString() + ", " + oldZco.ToString() + ")";
oldChunk2 = "Chunk (" + (oldXco + chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco+chunkWidth).ToString() + ")";
oldChunk3 = "Chunk (" + (oldXco + chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + oldZco.ToString() + ")";
oldChunk4 = "Chunk (" + (oldXco + chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco * -1).ToString() + ")";
oldChunk5 = "Chunk (" + (oldXco + chunkWidth * -1).ToString() + ", " + oldYco.ToString() + ", " + (oldZco+chunkWidth).ToString() + ")";
oldChunk6 = "Chunk (" + (oldXco + chunkWidth * -1).ToString() + ", " + oldYco.ToString() + ", " + oldZco.ToString() + ")";
oldChunk7 = "Chunk (" + (oldXco + chunkWidth * -1).ToString() + ", " + oldYco.ToString() + ", " + (oldZco * -1).ToString() + ")";
oldChunk8 = "Chunk (" + oldXco.ToString() + ", " + oldYco.ToString() + ", " + (oldZco + chunkWidth).ToString() + ")";
oldChunk9 = "Chunk (" + oldXco.ToString() + ", " + oldYco.ToString() + ", " + (oldZco * -1).ToString() + ")";
oldChunk10= "Chunk (" + (oldXco + chunkWidth * -2).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + 2 * chunkWidth).ToString() + ")";
oldChunk11= "Chunk (" + (oldXco + chunkWidth * -2).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + chunkWidth).ToString() + ")";
oldChunk12= "Chunk (" + (oldXco + chunkWidth * -2).ToString() + ", " + oldYco.ToString() + ", " + oldZco.ToString() + ")";
oldChunk13= "Chunk (" + (oldXco + chunkWidth * -2).ToString() + ", " + oldYco.ToString() + ", " + (oldZco * -1).ToString() + ")";
oldChunk14= "Chunk (" + (oldXco + chunkWidth * -2).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + -2 * chunkWidth).ToString() + ")";
oldChunk15= "Chunk (" + (oldXco + chunkWidth * -1).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + 2 * chunkWidth).ToString() + ")";
oldChunk16= "Chunk (" + (oldXco + chunkWidth * -1).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + -2 * chunkWidth).ToString() + ")";
oldChunk17= "Chunk (" + oldXco.ToString() + ", " + oldYco.ToString() + ", " + (oldZco + 2 * chunkWidth).ToString() + ")";
oldChunk18= "Chunk (" + oldXco.ToString() + ", " + oldYco.ToString() + ", " + (oldZco + -2 * chunkWidth).ToString() + ")";
oldChunk19= "Chunk (" + (oldXco + chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + 2 * chunkWidth).ToString() + ")";
oldChunk20= "Chunk (" + (oldXco + chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + -2 * chunkWidth).ToString() + ")";
oldChunk21= "Chunk (" + (oldXco + 2 * chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + 2 * chunkWidth).ToString() + ")";
oldChunk22= "Chunk (" + (oldXco + 2 * chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + chunkWidth).ToString() + ")";
oldChunk23= "Chunk (" + (oldXco + 2 * chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + oldZco.ToString() + ")";
oldChunk24= "Chunk (" + (oldXco + 2 * chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco * -1).ToString() + ")";
oldChunk25= "Chunk (" + (oldXco + 2 * chunkWidth).ToString() + ", " + oldYco.ToString() + ", " + (oldZco + -2 * chunkWidth).ToString() + ")";
}
}
}
if(oldChunk1.Equals(chunk1)){load1 = false;}
if(oldChunk2.Equals(chunk2)){load2 = false;}
if(oldChunk3.Equals(chunk3)){load3 = false;}
if(oldChunk4.Equals(chunk4)){load4 = false;}
if(oldChunk5.Equals(chunk5)){load5 = false;}
if(oldChunk6.Equals(chunk6)){load6 = false;}
if(oldChunk7.Equals(chunk7)){load7 = false;}
if(oldChunk8.Equals(chunk8)){load8 = false;}
if(oldChunk9.Equals(chunk9)){load9 = false;}
if(oldChunk10.Equals(chunk10)){load10 = false;}
if(oldChunk11.Equals(chunk11)){load11 = false;}
if(oldChunk12.Equals(chunk12)){load12 = false;}
if(oldChunk13.Equals(chunk13)){load13 = false;}
if(oldChunk14.Equals(chunk14)){load14 = false;}
if(oldChunk15.Equals(chunk15)){load15 = false;}
if(oldChunk16.Equals(chunk16)){load16 = false;}
if(oldChunk17.Equals(chunk17)){load17 = false;}
if(oldChunk18.Equals(chunk18)){load18 = false;}
if(oldChunk19.Equals(chunk19)){load19 = false;}
if(oldChunk20.Equals(chunk20)){load20 = false;}
if(oldChunk21.Equals(chunk21)){load21 = false;}
if(oldChunk22.Equals(chunk22)){load22 = false;}
if(oldChunk23.Equals(chunk23)){load23 = false;}
if(oldChunk24.Equals(chunk24)){load24 = false;}
if(oldChunk25.Equals(chunk25)){load25 = false;}
Debug.Log("1" + chunk1 + oldChunk1 + load1);
Debug.Log("2" + chunk2 + oldChunk2 + load2);
Debug.Log("3" + chunk3 + oldChunk3 + load3);
Debug.Log("4" + chunk4 + oldChunk4 + load4);
Debug.Log("5" + chunk5 + oldChunk5 + load5);
Debug.Log("6" + chunk6 + oldChunk6 + load6);
Debug.Log("7" + chunk7 + oldChunk7 + load7);
Debug.Log("8" + chunk8 + oldChunk8 + load8);
Debug.Log("9" + chunk9 + oldChunk9 + load9);
Debug.Log("10" + chunk10 + oldChunk10 + load10);
Debug.Log("11" + chunk11 + oldChunk11 + load11);
Debug.Log("12" + chunk12 + oldChunk12 + load12);
Debug.Log("13" + chunk13 + oldChunk13 + load13);
Debug.Log("14" + chunk14 + oldChunk14 + load14);
Debug.Log("15" + chunk15 + oldChunk15 + load15);
Debug.Log("16" + chunk16 + oldChunk16 + load16);
Debug.Log("17" + chunk17 + oldChunk17 + load17);
Debug.Log("18" + chunk18 + oldChunk18 + load18);
Debug.Log("19" + chunk19 + oldChunk19 + load19);
Debug.Log("20" + chunk20 + oldChunk20 + load20);
Debug.Log("21" + chunk21 + oldChunk21 + load21);
Debug.Log("22" + chunk22 + oldChunk22 + load22);
Debug.Log("23" + chunk23 + oldChunk23 + load23);
Debug.Log("24" + chunk24 + oldChunk24 + load24);
Debug.Log("25" + chunk25 + oldChunk25 + load25);
/*
//V1
if(load1){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco, yco, zco), Quaternion.identity);}
//V2
if(load2){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth, yco, zco + chunkWidth), Quaternion.identity);}
if(load3){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth, yco, zco), Quaternion.identity);}
if(load4){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth, yco, zco * -1), Quaternion.identity);}
if(load5){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -1, yco, zco + chunkWidth), Quaternion.identity);}
if(load6){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -1, yco, zco), Quaternion.identity);}
if(load7){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -1, yco, zco * -1), Quaternion.identity);}
if(load8){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco, yco, zco + chunkWidth), Quaternion.identity);}
if(load9){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco, yco, zco * -1), Quaternion.identity);}
//V3
if(load10){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -2, yco, zco + 2 * chunkWidth), Quaternion.identity);}
if(load11){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -2, yco, zco + chunkWidth), Quaternion.identity);}
if(load12){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -2, yco, zco), Quaternion.identity);}
if(load13){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -2, yco, zco * -1), Quaternion.identity);}
if(load14){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -2, yco, zco + -2 * chunkWidth), Quaternion.identity);}
if(load15){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -1, yco, zco + 2 * chunkWidth), Quaternion.identity);}
if(load16){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth * -1, yco, zco + -2 * chunkWidth), Quaternion.identity);}
if(load17){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco, yco, zco + 2 * chunkWidth), Quaternion.identity);}
if(load18){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco, yco, zco + -2 * chunkWidth), Quaternion.identity);}
if(load19){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth, yco, zco + 2 * chunkWidth), Quaternion.identity);}
if(load20){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + chunkWidth, yco, zco + -2 * chunkWidth), Quaternion.identity);}
if(load21){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + 2 * chunkWidth, yco, zco + 2 * chunkWidth), Quaternion.identity);}
if(load22){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + 2 * chunkWidth, yco, zco + chunkWidth), Quaternion.identity);}
if(load23){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + 2 * chunkWidth, yco, zco), Quaternion.identity);}
if(load24){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + 2 * chunkWidth, yco, zco * -1), Quaternion.identity);}
if(load25){Instantiate(terrains[Random.Range(0,terrains.length)], Vector3(xco + 2 * chunkWidth, yco, zco + -2 * chunkWidth), Quaternion.identity);}
*/
}
最佳答案
http://answers.unity3d.com/questions/177931/tutorial-minecraft-chunks.html
这是指向 UnityAnswers 的链接,其中包含有关如何在 Unity3D 中分块的教程。您可以在那里查看更多信息,并希望能找到您问题的答案。
关于algorithm - Unity3d 地形生成实例化到很多预制件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587841/
示例:https://www.terraform.io/docs/providers/kubernetes/r/service_account.html 我们看到了: resource "kubern
示例:https://www.terraform.io/docs/providers/kubernetes/r/service_account.html 我们看到了: resource "kubern
我有 5 个 keyvaults,有 5 个 secret ,问题是我不希望我的 terraform 文件有 10 个这样的数据 block : data "azurerm_key_vault" "k
我之前在我的 TF 代码中使用过这个: count = "${var.whatever == "true" ? 1 : 0}" 这非常适合我想要使用的东西。但是,我正在考虑如何最好地使用类似于说的
我之前在我的 TF 代码中使用过这个: count = "${var.whatever == "true" ? 1 : 0}" 这非常适合我想要使用的东西。但是,我正在考虑如何最好地使用类似于说的
我想创建一个上面有山的地形,使用一个非常基本的原理,如这个高度映射所示: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
根据文档,使用terraform,我能够在 digital ocean 上创建一个小滴: resource "digitalocean_volume" "foobar" { region
在 Terraform 中,我正在尝试创建一个模块,其中包含一个带有变量键的 map 。我不确定这是否可能,但我尝试了以下但没有成功。 resource "aws_instance" "web" {
我正在使用Box2d进行自行车物理游戏,Box2d可以让你拥有8点或更少的凸多边形的固定装置,有人知道更简单的方法吗除了制作一大堆固定装置之外,还有复杂的凹形地形?或者这是唯一的方法? 任何想法、指示
我正在尝试在 LWJGL 中制作 2D 游戏。我在地形生成方面遇到问题。 我目前有一个生成地形的算法,但它总是随机的,我永远无法再次获得相同的世界,我想制作一个基于生成 x 和 y 坐标的算法给定的数
我在使用 libgdx 和 box2d 进行卡车游戏。 在我的游戏中 1 米 = 100 像素。 我的 2d 地形是由我生成的,由点组成。 我所做的是为整个多边形制作了一个多边形区域并使用了textu
我有一个 3D boolean 值数组,代表一些 3D 地形。目前我可以通过在数组中的 x y 和 z 指定的位置绘制一个点来绘制它,它看起来像这样。 我想不通的是如何使用三角形绘制它,所以它看起来像
我读过很多关于这个概念的教程,但我觉得它们都没有深入探讨如何做到这一点。我已经知道 3D 编程(光栅化、投影矩阵等)、光线转换(使用欧几里得几何和矢量)和光线追踪如何工作,我只需要知道如何使用柏林噪声
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我正在做一些地形渲染,但遇到了一些麻烦。在这个时间点,我只是镶嵌顶点补丁,然后用高度图替换它们。我目前的问题是渲染看起来很时髦。我已经调试了一段时间,看起来这是深度缓冲区的问题。除此之外,我对正在发生
在 OpenGL 中用四边形制作地形纹理的最佳方法是什么?我有大约 30 种不同的纹理我想为我的地形(每种地形类型 1 个纹理,所以 30 种地形类型)并且希望在任何两个地形之间平滑过渡。 我一直在浏
执行时 terraform plan我没有错误,但是当我执行 terraform apply 时我收到以下错误。 地形计划输出:- + aws_route53_record.alm_route_rec
执行 terraform init 时出现以下错误升级到 0.12.2 后的命令版本。早期的相同代码在 terraform 中运行良好,没有问题 0.11.10版本。 alb.tf tags {
terraform init成功初始化但卡在 terraform 计划上。 该错误与功能块有关。我不确定在哪里添加功能块: Insufficient features blocks (source c
我正在使用 terraform 版本 0.14.3。我有一个用于创建 Azure 网络接口(interface)卡的模块,如下所示: resource "azurerm_network_interfa
我是一名优秀的程序员,十分优秀!