2014-08-14 19:47:13|?次阅读|上传:huigezrx【已有?条评论】发表评论
关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网
第一人称射击指南讲解如何去替代一个角色利用一个布娃娃版本和同步四肢最后状态的动画。你以在指南页发现那个指南。
Placing a bunch of objects in a specific pattern把一束对象放一个特定的图案中
Lets say you want to place a bunch of objects in a grid or circle pattern. Traditionally this would be done by either:
对你来说想要把一束物件放一个方格里或圆周图案中。传统地会采用下列之一做:
在场景里,制造完全装配的对象,复制它并放置它多次。这是沉闷的,而且正确放置对象在网格里是困难的。
So use Instantiate() with a Prefab instead! We think you get the idea of why Prefabs are so useful in these scenarios. Here's the code necessary for these scenarios:
因此使用Instantiate()与一个预制品替代。我们认为你获得一个想法:在这些场景里为什么预制品是如此有用。这些场景所需的代码在这里:
// Instantiates a prefab in a circle
var prefab : GameObject;
var numberOfObjects = 20;
var radius = 5;
function Start () {
for (var i = 0; i < numberOfObjects; i++) {
var angle = i * Mathf.PI * 2 / numberOfObjects;
var pos = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
Instantiate(prefab, pos, Quaternion.identity);
}
}
// Instantiates a prefab in a grid
var prefab : GameObject;
var gridX = 5;
var gridY = 5;
var spacing = 2.0;
function Start () {
for (var y = 0; y < gridY; y++) {
for (var x=0;x<gridX;x++) {
var pos = Vector3 (x, 0, y) * spacing;
Instantiate(prefab, pos, Quaternion.identity);
}
}
}