- Home /
C# Construct Line Links Over Time
I'm trying to make script where when gameObject enters another gameObject's Physics.OverlapSphere the gameObject adds it to gos and create line links between a series of gameobjects within each gameobjects Physics.OverlapSpheres. I've added the scripted gameobject to gos so gos wouldn't be null but the aren't being created. Is there something wrong with the logic of my script?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class LaserZigZag : MonoBehaviour {
public List<GameObject> gos = new List<GameObject>();
public Collider[] cols;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update() {
for (int i = 0; i < gos.Count -1; i++){
cols = Physics.OverlapSphere(gos[i].transform.position, 5f);
if(cols[i+1].gameObject == gos[i]){
gos.Add(cols[i+1].gameObject);
}
}
for (int i = 0; i < gos.Count -1; i++)
if (Physics.Linecast(gos[i].transform.position, gos[i+1].transform.position)){
Debug.DrawLine(gos[i].transform.position, gos[i+1].transform.position, Color.red);
}
}
}
I'm not sure why you're doing the Physics.Linecast at the end, but the debug line will only show for 1 frame, and only if you have gizmos enabled.
The Debug.DrawLine is only a placeholder. I plan to add a line renderer once I've got my LaserZigZag script fully fleshed out.
Your answer
Follow this Question
Related Questions
C# Check Physics.Raycast Once 0 Answers
Trouble Understanding Vector3.Angle() Result 2 Answers
RigidBody Script Conflict 1 Answer