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 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.

avatar image Protoyon JedBeryll · Jan 11, 2016 at 02:56 PM 0
Share

Sorry for the long wait, but the characters move and rotate script will be disabled, and the arrow image will display and flash properly, yet the chat and text do not appear

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

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

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

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

is it possible to take a simple game and run it super-fast with the graphics turned off, having 2 AIs playing against each other? 1 Answer


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