So I am shooting coloured darts at a spinning board. When the dart hits the board it will perform a check using Physics2D.OverlapCircleAll for any nearby darts which are of the same colour. If there are any detected it will add them to a list called Links. I want to be able to compare the other dart’s Link list with the current dart and if there is any differences to be able to add that to the current list.
![public class DartOptimized : MonoBehaviour
{
// Speed of the Dart
public float Velocity;
// Board transform
Transform boardTransform;
// This dart transform
Transform thisDartTransform;
//This dart layer
LayerMask thisLayer;
// Stopping distance for dart
public float boardContact;
// Distance to check for surrounding darts once contact is made with the board
public float checkRadius;
// Links list
public List<GameObject> Links = new List<GameObject>();
// Material for line
public Material LineRenderMat;
// Game Manager Script for score
GameManagerScript GM;
public Collider2D[] checkForSurroundingDarts;
private void Start()
{
boardTransform = GameObject.FindGameObjectWithTag("Board").transform;
thisDartTransform = gameObject.transform;
thisLayer = gameObject.layer;
GM = GameObject.FindObjectOfType<GameManagerScript>();
}
private void Update()
{
if (gameObject.tag == "Dart")
{
// Distance between the board and this dart
float distance = Vector3.Distance(boardTransform.position, thisDartTransform.position);
if (distance > boardContact)
{
// Move Dart
transform.Translate(new Vector3(0f, Velocity * Time.deltaTime, 0f));
}
else
{
gameObject.tag = "Pinned";
Invoke("AttachDartToBoard", 0);
}
}
}
private void AttachDartToBoard()
{
this.gameObject.transform.SetParent(boardTransform);
GM.scoreValue++;
checkForSurroundingDarts = Physics2D.OverlapCircleAll(transform.position, checkRadius);
for (var i = 0; i < checkForSurroundingDarts.Length; i++)
{
if (checkForSurroundingDarts_.gameObject.tag == "Pinned" && checkForSurroundingDarts*.gameObject.layer == this.gameObject.layer)*_
{
if (checkForSurroundingDarts*.gameObject.GetComponent().Links.Count <= 1)*
{
Links.Add(checkForSurroundingDarts*.gameObject);*
}
else if (checkForSurroundingDarts*.gameObject.GetComponent().Links.Count > 1)*
{
Links.Add(checkForSurroundingDarts*.gameObject);*
//Links.AddRange(checkForSurroundingDarts*.gameObject.GetComponent().Links);*
}
}
}
}][1]
_*