Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by strudi1986 · Feb 09, 2018 at 08:52 PM · prefabsprefab connection

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<FirstPersonController> ();
              toggleCursor = GameObject.FindObjectOfType<GameManager_ToggleCursor> ();
  
          }
          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

why is this so? thanks for help!

pic3.jpg (129.9 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathanvj · Feb 09, 2018 at 09:51 PM 0
Share

Could you include your $$anonymous$$eypad script, please? That would be helpful.

avatar image strudi1986 · Feb 09, 2018 at 10:38 PM 0
Share

i dont know why the prefab dont work by itself. my problem is that the 2 prefabs share the same eventcamera set in the canvas. but the camera jumps everytime to the prefab on the right (i placed the second prefab on the left from the first). because of this i see the left prefab on the screen but the input events happen on the other one. if i have only one prefab of this in the scene everything works correctly! i have no idea why always the camera on the original prefab will be activated?!

@nathanvj

@Legend_Bacon

avatar image pako · Feb 10, 2018 at 04:40 PM 0
Share

@strudi1986 please don't post your code as an answer. Just edit your original question and add the code, which I've done for you this time. But please delete your "answer", it's confusing.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

79 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instances of the same prefab behaving differently 0 Answers

How to safely delete a prefab? 0 Answers

Linking a Prefab as Variant to Another Prefab After Creation 0 Answers

Communicate between scenes with prefabs? 3 Answers

Prefabs floating in the air 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges