50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace Level14 {
|
|
public class Bullet14 : BulletStats {
|
|
int _currentBounces;
|
|
|
|
[SerializeField] Sprite red, yellow;
|
|
|
|
protected override void Start() {
|
|
base.Start();
|
|
|
|
_currentBounces = maxBounces;
|
|
}
|
|
|
|
void FixedUpdate() {
|
|
if (Rb.velocity.y <= maxYSpeed) return;
|
|
Vector2 velocity = Rb.velocity;
|
|
velocity.y = maxYSpeed;
|
|
Rb.velocity = velocity;
|
|
}
|
|
|
|
public void AddForce(int direction) {
|
|
++PlayerMovement14.instance.Bullets;
|
|
GetComponent<Rigidbody2D>().velocity = Vector2.right * direction * bulletSpeed;
|
|
}
|
|
|
|
void OnCollisionEnter2D(Collision2D other) {
|
|
transform.DOPunchScale(transform.localScale * 1.5f, .1f);
|
|
|
|
DOTween.Sequence()
|
|
.AppendCallback(() => {
|
|
Sprite.sprite = yellow;
|
|
}).AppendInterval(.1f)
|
|
.AppendCallback(() => {
|
|
Sprite.sprite = red;
|
|
});
|
|
|
|
--_currentBounces;
|
|
if (_currentBounces != 0 || other.gameObject.CompareTag("Enemy")) return;
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
void OnDestroy() {
|
|
--PlayerMovement14.instance.Bullets;
|
|
}
|
|
}
|
|
}
|