キーボードに押された数字をGetKeyDownで判断してその数字をpublicに代入して
ublic class InputManager : MonoBehaviour {
public int Answer;
// Use this for initialization void Start() { }
void Update () {
if (Input.GetKeyDown(KeyCode.Alpha0)) { Answer = 0; } if (Input.GetKeyDown(KeyCode.Alpha1)) { Answer = 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { Answer = 2; }
他のスクリプトからGetComponentで取得しようとしたのですが
public class Check : MonoBehaviour {
public GameObject IP;
public InputManager scripta;
public int A;
void Start () {
IP = GameObject.Find("InputManager");
scripta = IP.GetComponent<InputManager>();
A= scripta.Answer;
Debug.Log(A);
}
Aの値がDebugもInspectorも0のままになるんですが。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/30 02:46
2017/10/01 02:06