2017-11-10 9 views
0

私は大学のクラスのための非常に短い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);  
    } 
} 
+1

リプレイロジックがどのように機能するか尋ねるとどうなりますか?それは期待どおりに動作していない部分なので、解決策を見つけるのに役立ちます。 –

+0

@MaglethongSpirr確かに、コメントに十分な単語スペースがないので、私は元の質問にそのスクリプトを入れます。 –

+0

それを再アクティブ化するには、 ' .SetActive(true)'を呼び出すことを忘れてしまったようです。それは可能ですか?または、それは 'PlayerController.gameOver = false'である可能性がありますか?独自のスクリプトの中でプレイヤーを再起動しようとすると、 'SetActive(false)'で無効になったUnityメッセージ( 'Update()'や 'OnTriggerEnter()'など)は呼び出されないことに注意してください。 –

答えて

0

プレーヤーを有効にするか、新しいプレーヤーをインスタンス化する必要があります。

public void Replay() 
{ 
    //ReActivate 
    myPlayer.gameObject.SetActive(true); 

    //or Instnatiate a new 
    Instantiate(myPlayer); 
} 
+0

Hmmm ...私はこれを試すことができます。私は "myPlayer"変数を作成する必要がありますか、それともUnityのその部分ですか? –

+0

myPlayerを変数にして、プレイヤーオブジェクトをインスペクタのそのフィールドに参照する必要があります。 myPlayerオブジェクトは、OnTriggerEnterのこの変数に対応しています。 other.gameObject.SetActive(false); –

関連する問題