private void PickupForHeroe(Collision2D collision) { if (collision.collider.tag != "Player") { return; } RepeatedAudio.Get("SoulPickup_Audio").PlayTimes++; OnPickup.Invoke(); enabled = false; GetComponent <Collider2D>().enabled = false; Destroy(GetComponent <Rigidbody2D>()); var soulText = GameObject.Find("HeroHealth_Text").transform; var targetPosition = Camera.main.ScreenToWorldPoint(soulText.position); PickUpDelay += 0.1f; DOTween.Sequence() .Append(transform.DOMove(targetPosition, .5f + PickUpDelay)) .AppendCallback(() => { var stats = collision.collider.GetComponent <HeroStats>(); stats.Health += 5; Destroy(gameObject); }); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.name.StartsWith("Wall") && Time.time - _startTime < 0.05f) { return; } DamageEnemy(collision); FlashEnemy(collision); if (!Persistant) { if (_stats.BounceArrows && _bounces > 0) { RepeatedAudio.Get("EasyHit1_Audio").PlayTimes++; _bounces--; transform.up = transform.up - 2 * Vector3.Project(transform.up, collision.contacts[0].normal); } else { Destroy(gameObject); } } }
private void Update() { if (Input.GetMouseButtonDown(0) && !_bufferedArrow) { OnStretch.Invoke(); _downTime = Time.time; } if (Input.GetMouseButtonUp(0) || _bufferedArrow) { if (Time.time - _downTime < MinArrowStretchTime) { _bufferedArrow = true; return; } _bufferedArrow = false; OnShoot.Invoke(); RepeatedAudio.Get("ArrowShot_Audio").PlayTimes++; var arrow = Instantiate( _stats.AutoAim? AutoAimArrowPrefab : ArrowPrefab, transform.position, transform.rotation); var potential = Mathf.Min(1, ((Time.time - _downTime) / _stats.ArrowStretchTime)); arrow.GetComponent <ArrowFly>().Speed = _stats.ArrowMaxSpeed * Mathf.Max(0.6f, potential); var damage = Mathf.RoundToInt(_stats.ArrowDamage * potential); Debug.Log("Arrow Potential Damage: " + damage + " (" + _stats.ArrowDamage * potential + ")"); arrow.GetComponent <ArrowDamage>().Damage = damage; if (_stats.MultiShot) { var arrowCopy1 = Instantiate(arrow); arrowCopy1.GetComponent <ArrowFly>().Speed *= 0.8f; arrowCopy1.transform.Rotate(Vector3.forward, 15); if (Random.Range(0, _stats.BounceArrows ? 3 : 2) == 1) { arrowCopy1.GetComponent <ArrowDamage>().Damage = 0; } var arrowCopy2 = Instantiate(arrow); arrowCopy2.GetComponent <ArrowFly>().Speed *= 0.8f; arrowCopy2.transform.Rotate(Vector3.forward, -15); if (Random.Range(0, _stats.BounceArrows ? 3 : 2) == 1) { arrowCopy2.GetComponent <ArrowDamage>().Damage = 0; } } _downTime = Time.time; } }