public void GetAttracted(Vector3 force, ForceMode forceMode = ForceMode.VelocityChange) { if (!IsActive) { return; } OnPull?.Invoke(); switch (forceMode) { case ForceMode.Acceleration: _rb.AddForce(force, ForceMode.Acceleration); break; case ForceMode.VelocityChange: _rb.AddForce(force, ForceMode.VelocityChange); break; case ForceMode.Impulse: _rb.AddForce(force, ForceMode.Impulse); break; case ForceMode.Force: _rb.AddForce(force, ForceMode.Force); break; } }
private void OnTriggerEnter2D(Collider2D other) { if (Player.firstStep && other.tag == "Platform") { Platform platformScript = other.GetComponent <Platform>(); if (!platformScript.Used) { platform = other.transform; platformScript.Moving = false; Rigidbody.velocity = Vector2.zero; StartCoroutine(FixPosition(other.transform.position + other.transform.up * 0.8f, -other.transform.up)); if (Player.moving) { OnPull?.Invoke(); } platformScript.Used = true; } } if (other.tag == "Target") { Player.moving = false; Rigidbody.velocity = Vector2.zero; StartCoroutine(FixPosition(other.transform.position, -other.transform.up)); other.gameObject.SetActive(false); OnRestoreDefaults?.Invoke(); } if (other.tag == "GameOver") { OnGameOver?.Invoke(); } if (other.tag == "BounceEdge") { Rigidbody.velocity = -Rigidbody.velocity; } }
public override async Task Pull( PullRequest request, IServerStreamWriter <Rumor> responseStream, ServerCallContext context) { var pullEventArgs = new PullRumorEventArgs(); OnPull?.Invoke(this, pullEventArgs); if (pullEventArgs.Rumors != null) { using (var rumorsAsyncEnumerator = pullEventArgs.Rumors.GetEnumerator()) { while (!context.CancellationToken.IsCancellationRequested && rumorsAsyncEnumerator.MoveNext()) { await responseStream.WriteAsync(rumorsAsyncEnumerator.Current); } } } }
public void WithdrawOne() { var minDistance = float.PositiveInfinity; var knifeIndex = -1; for (int i = 0; i < knifesInAirList.Count; i++) { var distance = (knifesInAirList[i].transform.position - sheath.transform.position).sqrMagnitude; if (distance > minDistance || knifesInAirList[i].State == KnifeState.Flying || knifesInAirList[i].State == KnifeState.Returning) { continue; } minDistance = distance; knifeIndex = i; } if (knifeIndex >= 0) { List <ICanHandlePullingKnife> handlers = new List <ICanHandlePullingKnife>(); GetComponentsInChildren(handlers); if (knifesInAirList[knifeIndex].Stuck) { OnPull?.Invoke((knifesInAirList[knifeIndex].transform.position - transform.position).normalized); } if (knifesInAirList[knifeIndex].StuckOn != null) { foreach (var handler in handlers) { handler.OnPullingKnife(knifesInAirList[knifeIndex].StuckOn, knifesInAirList[knifeIndex]); } } knifesInAirList[knifeIndex].Withdraw(); } }