using DestroyIt; using UnityEngine; public class Bullet : MonoBehaviour { public float speed; public float damage; public Vector3 dir; // Start is called before the first frame update void Start() { GetComponent().velocity = transform.forward * speed; dir = transform.forward; } // Update is called once per frame void Update() { } private void OnCollisionEnter(Collision collision) { GetComponent().velocity = dir * speed; transform.forward = dir; if (collision.gameObject.GetComponent()) { HitEffects hitEffects = collision.gameObject.GetComponentInParent(); if (hitEffects != null && hitEffects.effects.Count > 0) hitEffects.PlayEffect(HitBy.Bullet, transform.position, transform.forward); DestroyIt.Destructible destructible = collision.gameObject.GetComponent(); destructible.ApplyDamage(damage); if (destructible.CurrentHitPoints > 0) { Destroy(gameObject); } } } }