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?
"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.
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612055724im_/https://answers.unity.com/themes/thub/images/avi.jpg)