動作確認
Unity 5.1.2 on MacOS X
トルクを調整してPlaneにCubeを着地させるゲーム。
code
CubeControl.cs
using UnityEngine;
using System.Collections;
public class CubeControl : MonoBehaviour {
public Rigidbody myRigid;
private int score = 0;
private bool gameEnd = false;
void Judge() {
float torq;
torq = Mathf.Abs( myRigid.angularVelocity.y );
print (torq.ToString ());
if (Mathf.Abs(torq - 3.0f) > Mathf.Epsilon) {
score = (int)(100000.0f / Mathf.Abs(torq - 3.0f));
} else {
score = 10000000;
}
}
void OnCollisionEnter() {
gameEnd = true;
Judge ();
}
void OnGUI() {
Rect rect1 = new Rect (10, 10, 100, 30);
GUI.TextField (rect1, score.ToString ());
}
void Update () {
if (gameEnd) {
return;
}
if (Input.GetKey (KeyCode.UpArrow)) {
myRigid.AddForce(Vector3.up);
}
if (Input.GetKey (KeyCode.DownArrow)) {
myRigid.AddForce(Vector3.down);
}
if (Input.GetKey(KeyCode.LeftArrow)) {
myRigid.AddTorque(Vector3.up);
}
if (Input.GetKey(KeyCode.RightArrow)) {
myRigid.AddTorque(Vector3.down);
}
}
}
準備
- Planeを追加 (Y: -0.5)
- Cubeを追加 (Y: 2.0)
- CubeにRigidBodyを追加 (Use Gravity:OFF)
- Cubeに上記スクリプトを関連づける
遊び方
上下カーソルでCubeが上下移動。
左右カーソルでCubeが左右回転。
左右回転をさせた状態でPlaneに着地させることで、判定が行われる。
トルクの絶対値が3付近で高得点。