2024-06-13 20:03:23 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class BulletMoving : MonoBehaviour
|
|
|
|
{
|
2024-06-14 19:08:04 +02:00
|
|
|
public GameObject child;
|
2024-06-13 20:03:23 +02:00
|
|
|
|
2024-06-14 10:35:34 +02:00
|
|
|
public DataBullet dataBullet;
|
2024-06-14 19:08:04 +02:00
|
|
|
|
|
|
|
public float lifetime = 3f;
|
2024-06-14 10:35:34 +02:00
|
|
|
[SerializeField]
|
|
|
|
private Rigidbody rb;
|
2024-06-13 20:03:23 +02:00
|
|
|
|
2024-06-14 16:58:09 +02:00
|
|
|
private Vector3 direction = new Vector3(0f,0f,0f);
|
|
|
|
|
2024-06-14 19:08:04 +02:00
|
|
|
private float time = 0f;
|
2024-06-14 16:58:09 +02:00
|
|
|
|
2024-06-14 19:08:04 +02:00
|
|
|
|
|
|
|
private void die(float lifetime){
|
|
|
|
if(time > lifetime){
|
|
|
|
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>();
|
|
|
|
direction = child.transform.position - transform.position;
|
2024-06-13 20:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2024-06-14 16:58:09 +02:00
|
|
|
rb.velocity = direction * dataBullet.speed;
|
2024-06-14 19:08:04 +02:00
|
|
|
die(lifetime);
|
|
|
|
time += Time.deltaTime;
|
2024-06-13 20:03:23 +02:00
|
|
|
}
|
|
|
|
}
|