private void HandleTouch() { if (Input.touchCount != 1) { return; } var touch = Input.touches[0]; if (touch.phase == TouchPhase.Began) { DragStartPosition = touch.position; transform.position = DragStartPosition; } else if (touch.phase == TouchPhase.Moved) { Hook.transform.position = touch.position; } else if (touch.phase == TouchPhase.Ended) { Vector2 delta = touch.position - DragStartPosition; SlingShootValue.Value = new Vector2( x: delta.x, y: delta.y ); OnSlingShootEvent.Invoke(); transform.position = InitialZonePosition; Hook.transform.position = InitialHookPosition; AvailableTime = Time.time + SlingShootDelay.Value; } }
protected override void Init() { var slingShootUnityEvent = new UnityEvent(); slingShootUnityEvent.AddListener(new UnityAction(OnSlingShoot)); SlingShootEvent.AddListener(slingShootUnityEvent); var energyDepletedUnityEvent = new UnityEvent(); energyDepletedUnityEvent.AddListener(new UnityAction(OnEnergyDepleted)); EnergyDepletedEvent.AddListener(energyDepletedUnityEvent); var winUnitytEvent = new UnityEvent(); winUnitytEvent.AddListener(new UnityAction(OnWin)); WinEvent.AddListener(winUnitytEvent); OnInfectiousChange += new System.Action <bool>((isInfected) => { if (isInfected) { InfectedEvent.Invoke(); } else { DeinfectedEvent.Invoke(); } }); }
/// <summary> /// Check is the serial port changed => check every 2 sec /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void SerialPortPinChanged(object source, ElapsedEventArgs e) { string[] sp = GetSerialPort(); if (!sp.SequenceEqual(_serialPort)) { _serialPort = sp; SerialEvent?.Invoke(this, new EventArgs()); Console.WriteLine("changed"); } }
public void OnCollide(ICollidable collidable, Vector2 delta) { PlayerPawn player = collidable as PlayerPawn; if (player == null) { return; } WinEvent.Invoke(); gameObject.SetActive(false); }
public Serial() { // Init serial port _serial = new SerialPort(); SerialEvent?.Invoke(this, new EventArgs()); // Init timer to handle serial port change _timerEvent = new Timer(); _serialPort = GetSerialPort(); _timerEvent.Elapsed += new ElapsedEventHandler(SerialPortPinChanged); _timerEvent.Interval = 2000; _timerEvent.Start(); }
public IEnumerator UpdateEnergyValue() { while (true) { yield return(new WaitForSeconds(1.0f)); Energy.Value -= (IsInfected ? 2.0f : 1.0f) / GameTimeInSeconds; if (Energy.Value <= 0) { break; } } EnergyDepleted.Invoke(); }