HI
So i tried to get gameobject in the scene using a raycast.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaypointController : MonoBehaviour
{
public GameObject[] neighbours;
public List<GameObject> viewingNeighbours;
RaycastHit hitInitialise;
public List<GameObject> pNeighbours;
void Start()
{
neighbours = GameObject.FindGameObjectsWithTag("Waypoint");
for (int i = 0; i < neighbours.Length; i++)
{
pNeighbours.Add(neighbours[i]);
}
for (int i = 0; i < pNeighbours.Count; i++)
{
Debug.DrawLine(transform.position, pNeighbours[i].transform.position, Color.blue, 2000);
if (Physics.Raycast(transform.position, pNeighbours[i].transform.position, out hitInitialise, 2000))
{
viewingNeighbours.Add(hitInitialise.collider.gameObject);
}
}
}
}
In the scene (picture) we can clearely see the blue lines going trough the colliders of the other capsules.
But… The list viewingNeighbourg does not get anything, stills empty.
I am assuming raycast neither, it deos not get anything neither.
What did i done wrong?
Thanks for help.