- Home /
Input variable from Inspector?
Is it possible to input a variable directly from the inspector?
For example, in the following script:
using UnityEngine;
using System.Collections;
public class StatusBar : MonoBehaviour {
public Color readyColor;
public Color almostReadyColor;
public bool flag;
void Update()
{
if (flag)
gameObject.guiTexture.color = readyColor;
else
gameObject.guiTexture.color = almostReadyColor;
}
}
I want to be able to use a different boolean for flag (such as a boolean from a different class) with different Game Objects. How can i do this? (C#)
...boolean from a different class) with different Game Objects.
C# GetComponent:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
http://unitygems.com/script-interaction1/
You are likely looking for dragging and dropping a reference to the class into your above script.
Answer by 305BigMoney · Aug 08, 2014 at 11:28 AM
well you can try this
[script 1]
using UnityEngine; using System.Collections;
public class StatusBar : MonoBehaviour
{
public StatusBar0 sb0;
public bool flag;
void Update()
{
if (flag)
gameObject.guiTexture.color = sbo.readyColor;
else
gameObject.guiTexture.color = sbo.almostReadyColor;
}
}
[script 2]
using UnityEngine;
using System.Collections;
public class StatusBar0 : MonoBehaviour
{
public Color readyColor;
public Color almostReadyColor;
}
i don't know if that what you mean you can put the original script on the desire object and put the StatusBar0 script on the other object an in the inspector drag the other object that has the SB0 script on it into the SB0 varable on the original object