I’m running an experiment (at a university) using Unity. I have a VR environment built in Unity.
I’d like to have a user interface where the research assistant can enter a participant ID # (e.g., 001) and certain game objects become active/inactive based on that number.
For example, if ID# 001 is entered in the UI then the light object is set to inactive in the environment. If ID# 002 is entered in the UI then the car-object in the environment is set to inactive. And so forth.
Can someone give me some tips on how to do this? I have 16 “conditions” to do this for (e.g., ID#01 - ID#16 all do something different).
Thanks. I can provide more explanation is the above is unclear.
Awesome. This is a huge step forward for me. I will try this out. Thank you.
My current script for the changes is based off of key presses:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VarController : MonoBehaviour
{
public GameObject FoV_Restricter;
public GameObject No_Shadow;
public GameObject Yes_Shadow;
public GameObject GrayScale;
public GameObject Thirty_FPS;
public GameObject Ninety_FPS;
// Start is called before the first frame update
void Start()
{
FoV_Restricter.SetActive(false);
No_Shadow.SetActive(false);
Yes_Shadow.SetActive(false);
GrayScale.SetActive(false);
Thirty_FPS.SetActive(false);
Ninety_FPS.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
FoV_Restricter.SetActive(true);
Debug.Log("Restricted_FOV_Set");
}
if (Input.GetKeyDown(KeyCode.F))
{
FoV_Restricter.SetActive(false);
Debug.Log("Unrestricted_FOV_Set");
}
if (Input.GetKeyDown(KeyCode.T))
{
No_Shadow.SetActive(true);
Debug.Log("No_Shadow_Set");
}
if (Input.GetKeyDown(KeyCode.G))
{
Yes_Shadow.SetActive(true);
Debug.Log("Yes_Shadow_Set");
}
if (Input.GetKeyDown(KeyCode.Y))
{
GrayScale.SetActive(false);
Debug.Log("Color_Set");
}
if (Input.GetKeyDown(KeyCode.H))
{
GrayScale.SetActive(true);
Debug.Log("Gray_Set");
}
if (Input.GetKeyDown(KeyCode.U))
{
Thirty_FPS.SetActive(true);
Debug.Log("30FPS_Set");
Ninety_FPS.SetActive(false);
Debug.Log("90FPS_OFF");
}
if (Input.GetKeyDown(KeyCode.J))
{
Ninety_FPS.SetActive(true);
Debug.Log("90FPS_Set");
Thirty_FPS.SetActive(false);
Debug.Log("30FPS_Off");
}
// To Clear/Reset all of the above.
if (Input.GetKeyDown(KeyCode.C))
{
FoV_Restricter.SetActive(false);
No_Shadow.SetActive(false);
Yes_Shadow.SetActive(false);
GrayScale.SetActive(false);
Thirty_FPS.SetActive(false);
Ninety_FPS.SetActive(false);
Debug.Log("ALL SETTINGS CLEARED");
}
}
}
So I could just put in that code where your code says “do something here” and enter in the changes for each number 1 through 16?
Yes. Not sure where you are doing the text inputs here, but you can figure that out pretty easy. where ever you have your input field set, you can add a button. then after you have input your information you click ok on the botton and then do something as the result.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VarController : MonoBehaviour
{
public GameObject FoV_Restricter;
public GameObject No_Shadow;
public GameObject Yes_Shadow;
public GameObject GrayScale;
public InputField _myInput; // My Changes
public GameObject Thirty_FPS;
public GameObject Ninety_FPS;
// Start is called before the first frame update
void Start()
{
FoV_Restricter.SetActive(false);
No_Shadow.SetActive(false);
Yes_Shadow.SetActive(false);
GrayScale.SetActive(false);
Thirty_FPS.SetActive(false);
Ninety_FPS.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
if(_myInput.text == "No1") /// My Changes
{
FoV_Restricter.SetActive(true);
Debug.Log("Restricted_FOV_Set");
}
}
if (Input.GetKeyDown(KeyCode.F))
{
FoV_Restricter.SetActive(false);
Debug.Log("Unrestricted_FOV_Set");
}
if (Input.GetKeyDown(KeyCode.T))
{
No_Shadow.SetActive(true);
Debug.Log("No_Shadow_Set");
}
if (Input.GetKeyDown(KeyCode.G))
{
Yes_Shadow.SetActive(true);
Debug.Log("Yes_Shadow_Set");
}
if (Input.GetKeyDown(KeyCode.Y))
{
GrayScale.SetActive(false);
Debug.Log("Color_Set");
}
if (Input.GetKeyDown(KeyCode.H))
{
GrayScale.SetActive(true);
Debug.Log("Gray_Set");
}
if (Input.GetKeyDown(KeyCode.U))
{
Thirty_FPS.SetActive(true);
Debug.Log("30FPS_Set");
Ninety_FPS.SetActive(false);
Debug.Log("90FPS_OFF");
}
if (Input.GetKeyDown(KeyCode.J))
{
Ninety_FPS.SetActive(true);
Debug.Log("90FPS_Set");
Thirty_FPS.SetActive(false);
Debug.Log("30FPS_Off");
}
// To Clear/Reset all of the above.
if (Input.GetKeyDown(KeyCode.C))
{
FoV_Restricter.SetActive(false);
No_Shadow.SetActive(false);
Yes_Shadow.SetActive(false);
GrayScale.SetActive(false);
Thirty_FPS.SetActive(false);
Ninety_FPS.SetActive(false);
Debug.Log("ALL SETTINGS CLEARED");
}
}
}