• 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 Protoyon · Jan 10, 2016 at 06:57 PM · c#instances

Issue With Multiple Instances of the same script

Hello, I am having a bit of a problem with a chat like script, basically, it'll only work in 1 place, I cannot have 2 instances of the script in the same scene, for only the first will work. Here is the script:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ReadSign2 : MonoBehaviour
 {
 
     public Image chat;
     public Text text;
     public Image arrow;
     public Image question;
     public string test;
     public string test1;
     public bool start;
     public bool start1;
     public bool hit_z;
     public Transform player;
     public Transform point;
 
     void Start()
     {
         // Text.SetActive(false);
         //Chat.SetActive(false);
         Disable();
     }
 
     void Update()
     {
         point.LookAt(player);
         var fwd = point.forward;
         RaycastHit hit;
                 if (Physics.Raycast(transform.position, fwd, out hit, 1.5f) && hit.collider.transform.gameObject.tag == "Player2" && hit_z == false && start == false)
                 {
                     start1 = true;
                     question.enabled = true;
                     if (Input.GetButtonDown("Interact1") && Physics.Raycast(transform.position, fwd, out hit, 1.5f) && hit.collider.transform.gameObject.tag == "Player2" && hit_z == false)
                     {
                                 StartCoroutine(wait(1));
                         }
 
                     
                 }
                 else
                 {
                     start1 = false;
                     question.enabled = false;
                 }
 
 
 
         if (start1 == false)
         {
             question.enabled = false;
         }
 
         if (start)
         {
             GameObject Movement = GameObject.Find("Thomas");
             Movement.GetComponent<Move1>().enabled = false;
             Movement.GetComponent<Rotate1>().enabled = false;
             text.enabled = true;
             chat.enabled = true;
 
 
             StartCoroutine(BlinkArrow());
 
             if (Input.GetButtonDown("Interact1"))
             {
                 hit_z = true;
                 start = false;
                 Disable();
             }
 
 
 
 
             text.text = test;
         }
     }
 
     void Disable()
     {
 
         if (start == false)
         {
             StartCoroutine(wait1(1));
             hit_z = false;
             text.text = "";
             GameObject Movement = GameObject.Find("Thomas");
             Movement.GetComponent<Move1>().enabled = true;
             Movement.GetComponent<Rotate1>().enabled = true;
             chat.enabled = false;
             text.enabled = false;
             arrow.enabled = false;
         }
     }
 
 
     IEnumerator wait(float blinkTime)
     {
         yield return new WaitForSeconds(0.01f);
         question.enabled = false;
         start1 = false;
         start = true;
     }
     IEnumerator wait1(float blinkTime)
     {
         yield return new WaitForSeconds(0.1f);
     }
     IEnumerator BlinkArrow()
     {
         while (start)
         {
             arrow.enabled = false;
             yield return new WaitForSeconds(1);
             if (start)
             {
                 arrow.enabled = true;
                 yield return new WaitForSeconds(1);
             }
         }
     }
 }
 

Can someone explain what's going on? I'm rather new to C#, so if I could also get any pointers to make this script better, I'd appreciate that.

But why does this script only work in 1 place?

Comment
Add comment · Show 2
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 JedBeryll · Jan 10, 2016 at 08:26 PM 0
Share

"Script doesn't work" is a little bit vague... What's wrong with it exactly? Does it throw an error? Some method can't be called? If it's an error then you should post that too.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

59 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

Related Questions

C# Use Multiple instances of Script or For Loop Once 1 Answer

Unity Stop Destroy(gameObject) destroyinng objects instantiated by this script 0 Answers

What is the need of the GetInstanceID() check in the following code? 1 Answer

How to interact with multiple instances of a single prefab? 1 Answer

How to set/change variables from an Editor Window on a Prefab 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