2024-06-16 21:54:47 +02:00
|
|
|
using System;
|
2024-06-13 20:03:23 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-06-16 21:54:47 +02:00
|
|
|
using Unity.VisualScripting;
|
2024-06-13 20:03:23 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
2024-06-16 13:50:01 +02:00
|
|
|
public class BulletScript : MonoBehaviour
|
2024-06-13 20:03:23 +02:00
|
|
|
{
|
2024-06-14 10:35:34 +02:00
|
|
|
public DataBullet dataBullet;
|
2024-06-21 11:28:03 +02:00
|
|
|
|
|
|
|
public GameObject particalClash;
|
2024-06-14 19:08:04 +02:00
|
|
|
|
|
|
|
public float lifetime = 3f;
|
2024-06-14 10:35:34 +02:00
|
|
|
private Rigidbody rb;
|
2024-06-13 20:03:23 +02:00
|
|
|
|
2024-06-16 13:25:46 +02:00
|
|
|
private Vector3 direction;
|
2024-06-14 16:58:09 +02:00
|
|
|
|
2024-06-14 19:08:04 +02:00
|
|
|
private float time = 0f;
|
2024-06-14 16:58:09 +02:00
|
|
|
|
2024-06-16 13:25:46 +02:00
|
|
|
private Ray ray;
|
|
|
|
private RaycastHit hit;
|
2024-06-14 19:08:04 +02:00
|
|
|
|
2024-06-27 08:55:02 +02:00
|
|
|
public void damageEnemy(float damageAmount){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-14 19:08:04 +02:00
|
|
|
private void die(float lifetime){
|
|
|
|
if(time > lifetime){
|
|
|
|
GameObject.Destroy(this.gameObject);
|
|
|
|
}
|
|
|
|
}
|
2024-06-16 13:25:46 +02:00
|
|
|
private void CheckForColliders(){
|
|
|
|
if(Physics.Raycast(ray, out hit)){ //wenn true wird durch out in variable hit ein RayCastHit gespeichert
|
|
|
|
direction = hit.point - transform.position;//Richtung in die, die Kugel fliegt
|
|
|
|
}
|
|
|
|
}
|
2024-06-16 21:54:47 +02:00
|
|
|
private void OnCollisionEnter(Collision collision){
|
2024-06-27 08:55:02 +02:00
|
|
|
Debug.Log(collision.gameObject.name + " UND HIER IST DER TAG: " + collision.gameObject.tag);
|
2024-06-21 11:28:03 +02:00
|
|
|
ContactPoint contact = collision.GetContact(0);
|
|
|
|
Instantiate(particalClash,transform.position,Quaternion.LookRotation(contact.normal));
|
2024-06-16 21:54:47 +02:00
|
|
|
GameObject.Destroy(this.gameObject);
|
|
|
|
}
|
2024-06-13 20:03:23 +02:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2024-06-14 19:08:04 +02:00
|
|
|
rb = this.GetComponent<Rigidbody>();
|
2024-06-16 13:25:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0f));
|
|
|
|
CheckForColliders();
|
2024-06-13 20:03:23 +02:00
|
|
|
}
|
2024-06-16 13:25:46 +02:00
|
|
|
|
2024-06-13 20:03:23 +02:00
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2024-06-16 13:50:01 +02:00
|
|
|
rb.velocity = direction.normalized * dataBullet.speed;
|
2024-06-14 19:08:04 +02:00
|
|
|
die(lifetime);
|
|
|
|
time += Time.deltaTime;
|
2024-06-13 20:03:23 +02:00
|
|
|
}
|
|
|
|
}
|