I’m trying to get a set of gameobject to connect to each with a Physics.LineCast. But I keep getting an error saying my argument is out of range. I think this is because i+1 doesn’t exist but I need that argument to make one gameobject link to another. Is there a way to work around this and make i+1 exist?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LaserZigZag : MonoBehaviour {
public List<GameObject> gos = new List<GameObject>();
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update() {
for (int i = 0; i < gos.Count; i++)
if (Physics.Linecast(gos*.transform.position, gos[i+1].transform.position)){*
_ Debug.DrawLine(gos*.transform.position, gos[i+1].transform.position, Color.red);_
_ }_
_}_
_}*_