Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 whiteman9 · Jul 05, 2016 at 11:57 AM · 5.3

How I'll do that when I come as a Player to some object , so the object will give me the key?

How I'll do that when I come as a Player to some object , so the object will give me the key? The point is that whenever I come into his BoxCollider , tells me that I bring him the key , that's ok . But when I'll get the key , I do not want to repeat , but I want to tell me something else. How should I do it? PS : the translation to Google . I come from Slovakia . PS2: DestroyWhenActivated It is a feature that does not need. PS3: Please advise someone , I've it all tangled up . Here are the scripts :

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class TextBoxManager : MonoBehaviour {

 public GameObject textBox;
 public GameObject textBox2;
 public Text theText;
 public Text theText2;
 public TextAsset textFile;  //pole pre Text
 public TextAsset textFile2;
 public string[] textLines;
 public string[] textLines2;
 public int currentLine;
 public int currentLine2;
 public int endAtLine;
 public int endAtLine2;
 public PlayerController player;
 public bool isActive;
 public bool isActive2;
  public bool destroyWhenActivated;
 public bool Lekarnicka;

 void Start () 
 {
     player = FindObjectOfType<PlayerController> ();
     Lekarnicka = false;
     isActive = false;

     if (textFile != null)
     {
         textLines = (textFile.text.Split ('\n'));
     }
     if (textFile2 != null)
     {
         textLines2 = (textFile2.text.Split ('\n'));
     }
     if (endAtLine == 0)
     {
         endAtLine = textLines.Length - 1;
     }
     if (endAtLine2 == 0)
     {
         endAtLine2 = textLines2.Length - 1;
     }
     if (isActive) 
     {
         EnableTextBox ();
     } 
     /*if (Lekarnicka) 
     {
         EnableTextBox2 ();
     }
         */
     else 
     {
         DisableTextBox ();
     }
 }
 void Update()
 {
     if (!isActive)
         {
             return;
         }
     theText.text = textLines [currentLine];
     if (Input.GetKeyDown (KeyCode.L)) 
         {
             currentLine += 1;
         }
     if (currentLine > endAtLine) 
         {
             DisableTextBox ();
         }
     if (Lekarnicka == true && isActive2 == true)
     {
         theText2.text = textLines2 [currentLine2];
         if (Input.GetKeyDown (KeyCode.L)) 
         {
             currentLine2 += 1;
         }
         if (currentLine2 > endAtLine2) 
         {
             DisableTextBox ();
         }
     }
 }

 public void EnableTextBox()
 {
     textBox.SetActive (true);
     isActive = true;
     {
         //player.canMove = false;
     }
 }

 public void EnableTextBox2()
 {
     textBox2.SetActive (true);
 }

 public void DisableTextBox()
 {
     textBox.SetActive (false);
     isActive = false;
     //textBox2.SetActive (false);
     }

 public void DisableTextBox2()
 {
     textBox2.SetActive (false);
     isActive2 = false;
 }
 public void ReloadScript2(TextAsset theText2)
 {
     if (theText2 != null) 
     {
         textLines2 = new string[1];
          textLines2 = (theText2.text.Split ('\n'));
      }
  }

 public void ReloadScript(TextAsset theText)
 {
     if (theText != null) 
     {
         textLines = new string[1];
         textLines = (theText.text.Split ('\n'));
      }
  }

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player" && (isActive = true)) 
     {
         Lekarnicka = false;
         textBox.SetActive (true);
         isActive = true;
         textBox2.SetActive (true);
         isActive2 = false;
     }
         if (destroyWhenActivated) 
         {
             Destroy (gameObject);
             if (gameObject)
             {
                 textBox.SetActive (false);
                 isActive = false;
                 textBox2.SetActive (false);
             }
         }

     if (other.gameObject.tag == "Lekarnicka") 
     {
         Lekarnicka = true;
         //isActive = true;
         isActive2 = true;
         if (isActive2 == true) 
         {
             isActive = false;
         }
     }
 }

 void OnTriggerExit(Collider other)
 {
     if (other.name == "Player") 
     {
         textBox.SetActive (false);
         isActive = false;
         textBox2.SetActive (false);
         DisableTextBox ();
           DisableTextBox2 ();
      }
  }

}

Second Script:

using UnityEngine; using System.Collections;

public class ActivateTextAtLine : MonoBehaviour { public TextAsset theText; public TextAsset theText2; public int startLine; public int startLine2; public int endLine; public int endLine2; public TextBoxManager theTextBox; public TextBoxManager2 theTextBox2; public bool isActive; public bool isActive2; public bool Lekarnicka; public bool destroyWhenActivated;

 void Start () 
 {
     isActive = false;
     isActive2 = false;
     if(isActive = false)
     {
         if (theTextBox = FindObjectOfType<TextBoxManager> ()) 
         {
             FindObjectOfType<TextBoxManager> ();
         }
     }
     /*if(isActive = true)    
     if (theTextBox2 = FindObjectOfType<TextBoxManager2> ()) 
     {
         FindObjectOfType<TextBoxManager2> ();
     }*/
 }


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

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player" && (isActive = false)) 
     {
         theTextBox.ReloadScript (theText);
         theTextBox.currentLine = startLine;
         theTextBox.endAtLine = endLine;
             theTextBox.EnableTextBox ();

         if (destroyWhenActivated) 
         {
             Destroy (gameObject);
         }
     }

     if (other.gameObject.tag == "Lekarnicka") 
     {
         Lekarnicka = true;
         isActive2 = true;
     }

     if (other.gameObject.tag == "Player" && Lekarnicka == true) 
     {
         theTextBox2.ReloadScript (theText2);
         theTextBox2.currentLine2 = startLine2;
         theTextBox2.endAtLine2 = endLine2;
         theTextBox2.EnableTextBox2 ();
     }
 }

}

Third Script:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class TextBoxManager2 : MonoBehaviour {

 public GameObject textBox2;
 public Text theText2;
 public TextAsset textFile2;  //pole pre Text
 public string[] textLines2;
 public int currentLine2;
 public int endAtLine2;
 public PlayerController player;
 public bool isActive;
 public bool destroyWhenActivated;
 public bool Lekarnicka;
 void Start () 
 {
     player = FindObjectOfType<PlayerController> ();

     Lekarnicka = false;
     isActive = false;

     if (textFile2 != null)
     {
         textLines2 = (textFile2.text.Split ('\n'));
     }

     if (endAtLine2 == 0)
     {
         endAtLine2 = textLines2.Length - 1;
     }

     if (isActive) 
     {
         EnableTextBox2 ();
     } 

     else 
     {
         DisableTextBox2 ();
     }
 }

 void Update()
 {
     /*if (!isActive)
     {
         return;
     }

 theText2.text = textLines2 [currentLine2];

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         currentLine2 += 1;
     }

     if (currentLine2 > endAtLine2) 
     {
         DisableTextBox2 ();
     }*/
 }

 public void EnableTextBox2()
 {
     textBox2.SetActive (true);
     isActive = true;
 }

 public void DisableTextBox2()
 {
     textBox2.SetActive (false);
     isActive = false;
 }

 public void ReloadScript(TextAsset theText2)
 {
     if (theText2 != null) 
     {
         textLines2 = new string[1];
         textLines2 = (theText2.text.Split ('\n'));
     }
 }

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Lekarnicka") 
     {
         Lekarnicka = true;
         textBox2.SetActive (true);
         isActive = true;
         //    FindObjectOfType<TextBoxManager2> ();
         //    FindObjectOfType<ActivateTextAtLine2> ();

     }
         if (destroyWhenActivated) 
         {
             Destroy (gameObject);
             if (gameObject)
             {
                 textBox2.SetActive (false);
                 isActive = false;
             }
         }    
     }

 void OnTriggerExit(Collider other)
 {
     if (other.name == "Player") 
     {
         textBox2.SetActive (false);
         isActive = false;
     }
 }

}

Comment
Add comment
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

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

60 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

Related Questions

Jittery Frame Rate with 120ms+ for PartilceSystem.GeometryJob execution 4 Answers

unity5.2版本烘焙Terrain, 阴影不清晰。 1 Answer

Cloth physics on a rigged character 1 Answer

Loading screen on 5.3 (problem after loading the first scene) 1 Answer

Preview of Prefabs broken since 5.6 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