私は大学のクラスのための非常に短いC#Unityゲームを作っています。私はプレイボタンを含む連絡先でプレイヤーを無効にするトラップのスクリプトを作成しました。それは私がリプレイをする以外はすべて動作します、プレーヤーは非アクティブのままです。 再生時にプレーヤーが再びアクティブになるようにスクリプトを修正するにはどうすればよいですか? また、私はこのクラスは初心者クラスですが、私はこれを上手くいきません。再生時にプレーヤーを再度アクティブにするにはどうすればよいですか?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Trap : MonoBehaviour
{
public GameObject playerExplosion;
public GameObject gameOverUI;
void OnTriggerEnter (Collider other)
{
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
}
other.gameObject.SetActive(false);
gameObject.SetActive(false);
gameOverUI.SetActive(true);
PlayerController.gameOver = false;
}
}
編集:ここでも再生スクリプトがあります。ヘルスバーシステムで動作します。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ReplayGame : MonoBehaviour
{
public Transform player;
public Image uiBar;
public GameObject GameOverUI;
public static Vector3 startPosition;
private float fillAmount;
void Start()
{
startPosition = player.position;
fillAmount = uiBar.fillAmount;
GameOverUI.SetActive(false);
}
public void Click()
{
PlayerController.gameOver = false;
player.position = startPosition;
uiBar.fillAmount = fillAmount;
GameOverUI.SetActive(false);
}
}
リプレイロジックがどのように機能するか尋ねるとどうなりますか?それは期待どおりに動作していない部分なので、解決策を見つけるのに役立ちます。 –
@MaglethongSpirr確かに、コメントに十分な単語スペースがないので、私は元の質問にそのスクリプトを入れます。 –
それを再アクティブ化するには、 ' .SetActive(true)'を呼び出すことを忘れてしまったようです。それは可能ですか?または、それは 'PlayerController.gameOver = false'である可能性がありますか?独自のスクリプトの中でプレイヤーを再起動しようとすると、 'SetActive(false)'で無効になったUnityメッセージ( 'Update()'や 'OnTriggerEnter()'など)は呼び出されないことに注意してください。 –