位置請勿重疊,把Floor移動到Cube01與Cube02兩個方塊的下方,並把Floor放大使其成為地板
複製程式碼貼到JavaScript上,然後拖曳到Cube01上執行
使用方向鍵或WASD鍵移控制Cube01碰撞Cube02
執行結果若看不清楚請放置一盞燈光
function Start() {
gameObject.Find("Cube01").AddComponent ("Rigidbody");
gameObject.Find("Cube02").AddComponent ("Rigidbody");
}
function Update() {
if (Input.GetKey ("down")||Input.GetKey (KeyCode.S)){
transform.Translate(0,0,5*Time.deltaTime);
}
if (Input.GetKey ("up")||Input.GetKey (KeyCode.W)){
transform.Translate(0,0,-5*Time.deltaTime);
}
if (Input.GetKey ("left")||Input.GetKey (KeyCode.A)){
transform.Rotate(0,-180*Time.deltaTime,0);
}
if (Input.GetKey ("right")||Input.GetKey (KeyCode.D)){
transform.Rotate(0,180*Time.deltaTime,0);
}
}
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.name == "Cube02") {
Destroy(collision.gameObject);
print("oh");
}
}
0 ♥:
張貼留言