void FixedUpdate() { if (completed) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Star star = hit.transform.gameObject.GetComponent <Star>(); if (star) { // For first star hovered, just add it as first point in the line if (!previous) { ActivateStar(star); } // For rest of stars, add point to line if star was not the previous star // Additionally, add edge to graph structure for checking completion else if (star != previous) { constellation.AddEdge(previous, star); ActivateStar(star); // If this edge completes the constellation, give visual indication if (constellation.IsComplete()) { completed = true; line.positionCount--; foreach (Star s in constellation.GetStars()) { s.Activate(); } return; } } previous = star; } } // Draw line to mouse position, so it looks like user is holding a thread connecting the stars Vector3 mousePos = Input.mousePosition; mousePos.z = transform.localPosition.z; mousePos = Camera.main.ScreenToWorldPoint(mousePos); mousePos = transform.InverseTransformPoint(mousePos); SetLastLinePoint(mousePos); }