PBG2H23ABR_PBG2H23AKL_PMC_P.../Plunderblock/Assets/Scripts/ScriptsKevin/BulletMoving.cs
2024-06-14 19:08:04 +02:00

40 lines
865 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletMoving : MonoBehaviour
{
public GameObject child;
public DataBullet dataBullet;
public float lifetime = 3f;
[SerializeField]
private Rigidbody rb;
private Vector3 direction = new Vector3(0f,0f,0f);
private float time = 0f;
private void die(float lifetime){
if(time > lifetime){
GameObject.Destroy(this.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
rb = this.GetComponent<Rigidbody>();
direction = child.transform.position - transform.position;
}
// Update is called once per frame
void Update()
{
rb.velocity = direction * dataBullet.speed;
die(lifetime);
time += Time.deltaTime;
}
}