using UnityEngine;

public class ExplodeBike : MonoBehaviour
{
    [System.Serializable]
    public class BikePart
    {
        public Transform part;
        public Vector3 explodeDirection;  // Richtung, in die das Teil explodiert
    }

    public BikePart[] bikeParts;
    public float explosionDistance = 2f;
    public float explosionSpeed = 2f;
    private bool isExploding = false;

    private Vector3[] originalPositions;

    void Start()
    {
        originalPositions = new Vector3[bikeParts.Length];
        for (int i = 0; i < bikeParts.Length; i++)
        {
            originalPositions[i] = bikeParts[i].part.localPosition;
        }
    }

    void Update()
    {
        if (isExploding)
        {
            for (int i = 0; i < bikeParts.Length; i++)
            {
                Vector3 targetPos = originalPositions[i] + bikeParts[i].explodeDirection.normalized * explosionDistance;
                bikeParts[i].part.localPosition = Vector3.Lerp(bikeParts[i].part.localPosition, targetPos, Time.deltaTime * explosionSpeed);
            }
        }
    }

    public void Explode()
    {
        isExploding = true;
    }
}



