Quantcast
Viewing all articles
Browse latest Browse all 103

Model as Prefab - lots of this prefab causing problems

Hi there! I have a problem. I have made a Keypad/Keylock Model with GUI in WorldSpace and Script on it. I have made a prefab with this Gameobject/Model. If i use one of this prefab in the scene everything works fine. but if i use this prefab more than 1 time in the scene i get problems. because the second prefab is talking with the first prefab. if i press a button on the second prefab, the button get pressed on the first prefab and on the second prefab nothing happens! why is this so? i show you a pic of the inspector variables! public class Keypad : MonoBehaviour { public string correctPassword; private string passwordInput; public Door affectedDoor; private int numberOne; private int numberTwo; private int numberThree; private int numberFour; public Text numberOneText; public Text numberTwoText; public Text numberThreeText; public Text numberFourText; private bool numberOneAdded = false; private bool numberTwoAdded = false; private bool numberThreeAdded = false; private bool numberFourAdded = false; private bool keypadActive = false; public Text passwordField; public Camera mainCam; public Camera keypadCam; public MeshCollider meshCol; private FirstPersonController playerController; private GameManager_ToggleCursor toggleCursor; void Start () { SetInitialReferences (); } void SetInitialReferences () { playerController = GameObject.FindObjectOfType (); toggleCursor = GameObject.FindObjectOfType (); } void Update () { if ( Input.GetKeyDown (KeyCode.Q) ) { LeaveKeypad (); } } public void MoveCameraToKeypad() { this.mainCam.enabled = false; playerController.enabled = false; this.gameObject.layer = LayerMask.NameToLayer ("Default"); toggleCursor.isCursorlocked = false; Cursor.visible = true; this.keypadActive = true; this.keypadCam.enabled = true; this.meshCol.enabled = false; } public void LeaveKeypad () { this.mainCam.enabled = true; playerController.enabled = true; toggleCursor.isCursorlocked = true; Cursor.visible = false; this.keypadCam.enabled = false; this.meshCol.enabled = true; if (keypadActive == false) { this.gameObject.layer = LayerMask.NameToLayer ("Default"); } else { this.gameObject.layer = LayerMask.NameToLayer ("Interactable"); } } public void CountNumberOneUp () { numberOne += 1; numberOneText.text = numberOne.ToString (); if(numberOne > 9 ) { numberOne = 0; numberOneText.text = numberOne.ToString (); } } public void CountNumberTwoUp () { numberTwo += 1; numberTwoText.text = numberTwo.ToString (); if(numberTwo > 9 ) { numberTwo = 0; numberTwoText.text = numberTwo.ToString (); } } public void CountNumberThreeUp () { numberThree += 1; numberThreeText.text = numberThree.ToString (); if(numberThree > 9 ) { numberThree = 0; numberThreeText.text = numberThree.ToString (); } } public void CountNumberFourUp () { numberFour += 1; numberFourText.text = numberFour.ToString (); if(numberFour > 9 ) { numberFour = 0; numberFourText.text = numberFour.ToString (); } } //Count numbers down public void CountNumberOneDown () { numberOne -= 1; numberOneText.text = numberOne.ToString (); if ( numberOne < 0 ) { numberOne = 9; numberOneText.text = numberOne.ToString (); } } public void CountNumberTwoDown () { numberTwo -= 1; numberTwoText.text = numberTwo.ToString (); if ( numberTwo < 0 ) { numberTwo = 9; numberTwoText.text = numberTwo.ToString (); } } public void CountNumberThreeDown () { numberThree -= 1; numberThreeText.text = numberThree.ToString (); if ( numberThree < 0 ) { numberThree = 9; numberThreeText.text = numberThree.ToString (); } } public void CountNumberFourDown () { numberFour -= 1; numberFourText.text = numberFour.ToString (); if ( numberFour < 0 ) { numberFour = 9; numberFourText.text = numberFour.ToString (); } } //Add numbers to the password field public void AddNumberOne () { if(numberOneAdded == false ) { passwordField.text = passwordInput += numberOne.ToString (); numberOneAdded = true; } } public void AddNumberTwo () { if ( numberTwoAdded == false && numberOneAdded == true ) { passwordField.text = passwordInput += numberTwo.ToString (); numberTwoAdded = true; } } public void AddNumberThree () { if ( numberThreeAdded == false && numberTwoAdded == true && numberOneAdded == true ) { passwordField.text = passwordInput += numberThree.ToString (); numberThreeAdded = true; } } public void AddNumberFour () { if ( numberFourAdded == false && numberThreeAdded == true && numberTwoAdded == true && numberOneAdded == true ) { passwordField.text = passwordInput += numberFour.ToString (); numberFourAdded = true; } } public void ResetNumbers () { passwordInput = ""; passwordField.text = ""; numberOneAdded = false; numberTwoAdded = false; numberThreeAdded = false; numberFourAdded = false; } public void CheckIfPasswordIsCorrect () { if(passwordInput == correctPassword ) { passwordField.text = "Access granted"; numberOneAdded = true; numberTwoAdded = true; numberThreeAdded = true; numberFourAdded = true; keypadActive = false; if(affectedDoor.lockedWithKeypad == true ) { affectedDoor.isDoorLocked = false; } StartCoroutine (WaitToLeaveAutomatic ()); } else { passwordField.text = "Access denied"; passwordInput = ""; numberOneAdded = false; numberTwoAdded = false; numberThreeAdded = false; numberFourAdded = false; } } IEnumerator WaitToLeaveAutomatic () { yield return new WaitForSeconds (2); LeaveKeypad (); } } ![alt text][1] [1]: /storage/temp/111033-pic3.jpg why is this so? thanks for help!

Viewing all articles
Browse latest Browse all 103

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>