Use String as a bool
Hi
I am trying to make an assembly line and need to check if the assembly is done correct. I have 5 parts which needs to be assembled in the natural order 1 to 5 (of cause). All the parts have the same script and i like to do a check if the correct part has been put down before the next one. instead of making 5 scripts I like to make only 1. I don't know if this is possibl.
My SceneManager (script) holds the bools for each part
public class SceneManager : MonoBehaviour
{
public bool assPart01;
public bool assPart02;
public bool assPart03;
public bool assPart04;
public bool assPart05;
}
The script for the parts:
public class PartsTransform : MonoBehaviour
{
public string awaits;
// the name of the part I am waiting for, part 2 waits for part 1 to be "true"
// the string name should be equal to the bools in the SceneManager.
public bool canAssembly;
// bool to hold the value from the SceneManager.
void OnCollisionEnter(Collision col)
{
GameObject projectManager = GameObject.Find("ProjectManager");
SceneManager sceneManager = projectManager.GetComponent<SceneManager>();
**canAssembly = sceneManager.awaits** // Problem here
if (canAssembly == true )
{
//make the assembly!
}
}
My Problem is, I don't know how to translate the string to a "name" on a variable/bool in the SceneManager
Your answer
![](https://koobas.hobune.stream/wayback/20220612151118im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Help] Getting variable based on string value. 2 Answers
checking a bool via string 0 Answers
I need help with calling a string 1 Answer
Blocky (pixelated) textures on build only (not in editor) 0 Answers