- Home /
Question by
Aqurom · Sep 09, 2020 at 11:47 PM ·
c#listvariablegetcomponentmonobehaviour
Get variable from Script in list and , set direct link to other script
Hello, trying to get value of variable in Script from List, and if its False, i need put direct link on this Script in other script... but i doing something wrong and cant get a value.
using System.Collections.Generic;
using UnityEngine;
public class ListHolder : MonoBehaviour
{
public List<MonoBehaviour> muIsBusy = new List<MonoBehaviour>();
private void Update()
{
AddMUInTheList();
}
void AddMUInTheList()
{
if (GameObject.FindObjectOfType<MU>() != null)
{
if (!muIsBusy.Contains(GameObject.FindObjectOfType<MU>())) muIsBusy.Add(GameObject.FindObjectOfType<MU>());
foreach (var scriptableThing in muIsBusy)
{
if (scriptableThing != null & scriptableThing.muBusy == false)
{
//set link to onher script
}
}
}
}
}
Here the scipt which variable i need:
using UnityEngine;
public class MU : MonoBehaviour
{
public static bool muBusy = false;
public int random;
public void Start()
{
random = Random.Range(0, 2);
if (random != 0)
{
muBusy = true;
}
}
}
Comment
Answer by Magso · Sep 10, 2020 at 12:30 AM
You can set it directly using GetComponent
muBusy = GetComponent<OtherScript>().muIsBusy[index];
Your answer
Follow this Question
Related Questions
Is it possible to use a variable as a Type? 1 Answer
Script reference from another c# script 2 Answers
Problem calling variable across scripts (Closed) 1 Answer
Creating an ordered list from a variable 1 Answer
A node in a childnode? 1 Answer