私はPing PongゲームをUnityの学習活動として取り組もうとしています。私はそれが永遠のために上下に跳ね上がっている場合、ピンポンボールのためのリセットシステムを作ることに取り組んでいます。一定期間後に変数を0に戻す方法
私はボールがゲームの上壁に当たった場合HitsTop
変数は1
同様に、底面の壁。私の問題は、ボールが底壁と上壁に10回当たったときにボールの位置をリセットすることです。
HitsTop
とHitsBottom
の変数を一定の時間、たとえば5秒後にリセットするコードを追加したいとします。
これはC#で可能ですか?
私のコードは次のような次のとおりです。
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public static int PlayerScore1 = 0;
public static int PlayerScore2 = 0;
public static int HitsTop = 0;
public static int HitsBottom = 0;
public GUISkin layout;
Transform theBall;
// Use this for initialization
void Start() {
theBall = GameObject.FindGameObjectWithTag("Ball").transform;
}
public static void Score (string wallID) {
if (wallID == "rightWall")
{
PlayerScore1++;
} else if (wallID == "leftWall") {
PlayerScore2++;
}
if (wallID == "topWallTrigger")
{
HitsTop++;
} else if (wallID == "bottomWallTrigger") {
HitsBottom++;
}
}
void OnGUI() {
GUI.skin = layout;
GUI.Label(new Rect(Screen.width/2 - 150 - 12, 20, 100, 100), "" + PlayerScore1 + HitsTop);
GUI.Label(new Rect(Screen.width/2 + 150 + 12, 20, 100, 100), "" + PlayerScore2 + HitsBottom);
if (GUI.Button(new Rect(Screen.width/2 - 60, 35, 120, 53), "RESTART"))
{
PlayerScore1 = 0;
PlayerScore2 = 0;
HitsTop = 0;
HitsBottom = 0;
theBall.gameObject.SendMessage("RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
}
if (PlayerScore1 == 10)
{
GUI.Label(new Rect(Screen.width/2 - 150, 200, 2000, 1000), "PLAYER ONE WINS");
theBall.gameObject.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
} else if (PlayerScore2 == 10)
{
GUI.Label(new Rect(Screen.width/2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
theBall.gameObject.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
}
if (HitsTop == 10) {
theBall.gameObject.SendMessage("RestartGame", 1.0f, SendMessageOptions.RequireReceiver);
HitsTop = 0;
} else if (HitsBottom == 10) {
theBall.gameObject.SendMessage("RestartGame", 1.0f, SendMessageOptions.RequireReceiver);
HitsBottom = 0;
}
}
}
にタイマーをリセットはい、それは、C#で可能です - いくつかのコードを投稿してください。 –