如何在 Unity3D 中单击鼠标创建对象的副本?
另外,如何在运行时选择要克隆的对象? (最好选择鼠标)。
最佳答案
function Update () {
var hit : RaycastHit = new RaycastHit();
var cameraRay : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (cameraRay.origin,cameraRay.direction,hit, 1000)) {
var cursorOn = true;
}
var mouseReleased : boolean = false;
//BOMB DROPPING
if (Input.GetMouseButtonDown(0)) {
drop = Instantiate(bomb, transform.position, Quaternion.identity);
drop.transform.position = hit.point;
Resize();
}
}
function Resize() {
if (!Input.GetMouseButtonUp(0)) {
drop.transform.localScale += Vector3(Time.deltaTime, Time.deltaTime,
Time.deltaTime);
timeD +=Time.deltaTime;
}
}
您会希望在多次调用 Update 的过程中发生这种情况:
function Update () {
if(Input.GetMouseButton(0)) {
// This means the left mouse button is currently down,
// so we'll augment the scale
drop.transform.localScale += Vector3(Time.deltaTime, Time.deltaTime,
Time.deltaTime);
}
}
关于unity-game-engine - 创建游戏对象的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3526941/