using UnityEngine; public class bulletScript : MonoBehaviour { private ShootScript shootScript; private float range, damage, unload, burst; private Rigidbody2D body; Vector3 startPos; void Awake() { shootScript = GameObject.Find("Player").GetComponent(); body = GetComponent(); range = shootScript.BulletRange; damage = shootScript.BulletDamage; unload = shootScript.BulletUnloadSpeed; burst = shootScript.BulletBurstAmount; startPos = transform.position; } void Update() { Vector3 currentPos = transform.position; if (Vector2.Distance(startPos, currentPos) > range) body.gravityScale = 1; if (currentPos.y < -1000) Destroy(gameObject); } void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Attackable")) { if (collision.GetComponent()) { collision.GetComponent().Health -= damage; Destroy(gameObject); } if (collision.GetComponent()) { if (collision.GetComponent().AttackableByPlayer) { collision.GetComponent().Health -= damage; Destroy(gameObject); } } } if (collision.gameObject.layer == 6) Destroy(gameObject); } }