// Use this for initialization void Start() { gazePointData = GetComponent <GazePointDataComponent>(); OpenSerialPort(); InvokeRepeating("SendControlData", 0, SEND_FREQUENCY); Application.LoadLevel("drive"); UnityArduino.SendImmediate("1"); UnityArduino.SetStreamControlData(true); }
void Update() { bool hasGaze = _bgGazeAware.HasGaze; //for now, just for debug if (Input.GetMouseButton(0)) { Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (_bgCollider2D.OverlapPoint(worldPos)) { hasGaze = true; } } if (lastActivateTime != TIME_NOT_SET) { if (Time.time - lastActivateTime < COOL_DOWN_DURATION) { hasGaze = false; } else { lastActivateTime = TIME_NOT_SET; } } //update gaze time if (hasGaze) { _bgTransform.Rotate(Vector3.forward); if (lastGazeTime == TIME_NOT_SET) { lastGazeTime = Time.time; } } else if (lastGazeTime != TIME_NOT_SET) { lastGazeTime = TIME_NOT_SET; } //respond to gaze time if (lastGazeTime == TIME_NOT_SET) { if (lastActivateTime == TIME_NOT_SET) { _bgSpriteRenderer.color = Color.red; } else { _bgSpriteRenderer.color = Color.green; } } else if (Time.time - lastGazeTime < ACTIVATE_THRESHOLD) { _bgSpriteRenderer.color = Color.yellow; } else { _bgSpriteRenderer.color = Color.green; if (targetScene != "") { Application.LoadLevel(targetScene); if (targetScene == "drive" || targetScene == "arm") { UnityArduino.SetStreamControlData(true); } else { UnityArduino.SetStreamControlData(false); } } if (controlData != "") { UnityArduino.SendImmediate(controlData); } lastActivateTime = Time.time; } }