Chain Lightning spell.

using UnityEngine;

public class Lightning : MonoBehaviour
{
public float damage;
Vector3 Lightingspeed;
public float speed = 50f;
public float radius = 5;
public GameObject Lightning;
public LineRenderer lineRenderer;

void Start()
{
    lineRenderer lineRenderer = gameObject.AddComponent<lineRenderer>();
    Lightingspeed = this.transform.forward * speed;
}

void OnCollisionEnter(Collision col)
{
    Debug.Log("shocked");

    Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius);
    foreach (Collider hitCol in hitColliders)
    {
        Debug.Log(hitCol.gameObject.name);
        EnemyHealth enemyHealth = hitCol.transform.GetComponent<EnemyHealth>();
        if (enemyHealth != null)
        {
            enemyHealth.TakeDamage(damage);
            Debug.Log(damage);
        }
    }
}

}

I’m trying to shoot a projectile that cast an overlapshere on hit and store a list of targets for the spell to bounce between. I’m not sure how to make the linerender follow the collider array.

(Not sure) Add the Transfom of every hitCol to an outside list every iteration. Then, at the end of the foreach you have the list of transforms which contains the .position of every object. Also it’s a refference so if the objects move the lightning would move as well (i think). You can make a new GameObject() and attach a LineRenderer to it, set it up with the values, and after the lightning you can remove it. Hope it helps.