using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class BulletScript : MonoBehaviour { public DataBullet dataBullet; private float damage; private float speed; private int ammo; public GameObject particalClash; public float lifetime = 3f; private Rigidbody rb; private float time = 0f; /// /// Sobald life Time vorbei ist Destroy die Bullet. /// /// Lifetime der Bullet private void die(float lifetime){ if(time > lifetime){ GameObject.Destroy(this.gameObject); } } /// /// clashPartical spawned clashPartical am EinschlagPunkt der Kugel. /// /// Die Collision mit der Bullet. public void clashParticle(Collision collision){ ContactPoint contact = collision.GetContact(0); Instantiate(particalClash,transform.position,Quaternion.LookRotation(contact.normal)); } /// /// Wenn die Bullet etwas behrührt zerstört sie sich selbst. /// /// Die Collision mit der Bullet private void OnCollisionEnter(Collision collision){ Debug.Log(collision.gameObject.name + " UND HIER IST DER TAG: " + collision.gameObject.tag); if(collision.transform.tag == "Enemy"){ collision.transform.GetComponent().takeDamage(damage); } clashParticle(collision); GameObject.Destroy(this.gameObject); } // Start is called before the first frame update void Start() { damage = dataBullet.damage; ammo = dataBullet.ammo; speed = dataBullet.speed; rb = this.GetComponent(); Physics.IgnoreCollision(GetComponent(),GameObject.Find("Player").GetComponent()); } // Update is called once per frame void Update() { rb.velocity = transform.forward * speed; die(lifetime); time += Time.deltaTime; } }