2016-11-30 5 views
-2

私は2つのスクリプトを持っていますが、私は最初のスクリプトのトリガーを他のスクリプトのトリガーを有効にするようにしようとしています。変数でonCollitionEnterを有効にする

私の最初のコードは

using UnityEngine; 
using System.Collections; 

public class endpoint10 : MonoBehaviour { 
public static int IsColliderEnabled; 
endpoint10.IsColliderEnabled = 0; 
void OnTriggerEnter(Collider other) 
{ 
    if (IsColliderEnabled = 1) { 
     //do stuff here 
     // The switch statement checks what tag the other gameobject is,  and reacts accordingly. 
     switch (other.gameObject.tag) { 
     case "end": 
      Debug.Log (other.gameObject.tag); 

      PlayerPrefs.SetInt ("moneyPref", scoreManager.money); 
      PlayerPrefs.SetInt ("scorePref", scoreManager.score); 
      ScoreSystem.level += 1; 
      PlayerPrefs.SetInt ("levelPref", ScoreSystem.level); 
      Debug.Log ("values stored"); 
      Application.LoadLevel ("level_11"); 
      break; 

     } 
    } 
    // Finally, this line destroys the gameObject the player collided with. 
    //Destroy(other.gameObject); 
} 

}

で、私の第二のコードは

using UnityEngine; 
using System.Collections; 

public class trigguercubex : MonoBehaviour { 

public GameObject[] objects; 

void OnTriggerEnter(Collider other) 
{ 
    endpoint10.IsColliderEnabled = 1; 
    Debug.Log (other.gameObject.tag); 



} 

    // Finally, this line destroys the gameObject the player collided with. 
    //Destroy(other.gameObject); 

}

+1

あなたはそれを実現するあなたのifステートメントでは、IsColliderEnabledの値を1に設定し、それが1 ... rightに等しいかどうかをテストしません。 – Alox

+0

はい最終的に私はいくつかの変更を行い、さらに2つの新しい変数を使用し、それらを変更する必要があります0から1を必要とするコードをテストしたが、私はまだテストしませんでした。いいえ、私はゲームマネージャーを使用していません。私は他のコードの開発者です。私はちょうど数週間前にjsとc#で始まります。 –

+0

そして、それは私の難しいことです、私はそれを比較する方法を知っているので、私は2つの新しい公共の変数を1つ1つをオフにしてそれを再生するためにそれを決定するwen私は必要とします –

答えて

1

あなたがゲームマネージャのスクリプトを持っていないのですか?衝突が

GameManager.instance.TriggerOccurred(); 
あなたtrigguercubexクラスで

if (GameManager.instance.IsTriggerOccurred) { 
    do some stuff(); 
} 

を検出したとき あなたは私が私のゲームのにGameManagerスクリプトを添付セッターとゲッターエンドポイントクラス で

using UnityEngine; 
using System.Collections; 

public class GameManager : MonoBehaviour { 

public static GameManager instance = null; 

private bool triggerredOccurred = false; 

public bool IsTriggerredOccurred { 
    get { return triggerredOccurred;} 
} 

public void TriggerredOccurred() { 
    triggerredOccurred = true; 
} 

void Awake(){ 
    if (instance == null) { //check if an instance of Game Manager is created 
     instance = this; //if not create one 
    } else if (instance != this) { 
     Destroy(gameObject); //if already exists destroy the new one trying to be created 
    } 

    DontDestroyOnLoad(gameObject); //Unity function allows a game object to persist between scenes 
} 

// Use this for initialization 
void Start() { 

} 

// Update is called once per frame 
void Update() { 

    } 
} 

を使用することができますメインカメラ

+0

こんにちは、そのエラーが来るGameManagerには定義が含まれていない –

関連する問題