/// <summary> /// If input signal is broadcast, check for movement actions /// </summary> /// <param name="signal"></param> /// <returns></returns> private bool OnInputSignal(InputSignal signal) { if ((signal.action & (int)Action.TurnLeft) == (int)Action.TurnLeft) { _angle += turnSpeed * Time.deltaTime; SetRotation(); } if ((signal.action & (int)Action.TurnRight) == (int)Action.TurnRight) { _angle -= turnSpeed * Time.deltaTime; SetRotation(); } if ((signal.action & (int)Action.Thrust) == (int)Action.Thrust) { _thrust = maxThrust; _thrustEmission.enabled = true; if (!thrustSound.isPlaying) { thrustSound.Play(); } } if ((signal.action & (int)Action.CeaseThrust) == (int)Action.CeaseThrust) { _thrustEmission.enabled = false; } return(true); }
/// <summary> /// When the input signal is broadcast, check to see if it includes a fire action. /// If so, instantiate the blaster at the ship's gun position /// </summary> /// <param name="signal"></param> /// <returns></returns> private bool OnInputSignal(InputSignal signal) { if ((signal.action & (int)Action.Fire) == (int)Action.Fire) { // get the ship's gun position by broadcasting a request for it List <SignalResponse <GetShipGunResponse> > responses; if (Signaler.Instance.Broadcast <GetShipGunRequest, GetShipGunResponse>(this, out responses) > 0) { // the ship acknowleged the broadcast and sent a response back. // use the response to set the position and orientation of the blaster. GameObject.Instantiate(blasterPrefab, responses[0].response.position, responses[0].response.orientation, this.transform); } } return(true); }