private void ClearLeaded(MagnetPattern other) { for (int i = 0; i < leaded.Count; i++) { other.leaded.Add(leaded[i]); leaded[i].leader = other; } //other.leaded = leaded; leaded.Clear(); }
public void SpawnChromosome(Vector3 position) { GameObject chromosome = (GameObject)GameObject.Instantiate(Chromosome, position, Quaternion.identity); MagnetPattern magnet = chromosome.GetComponent <MagnetPattern>(); magnet.id = nbChromosomes++; magnet.otherChromosomes = chromosomes; magnet.speed = Random.Range(2, 4); magnet.leadCapacity = Random.Range(5, 20); magnet.player = player; chromosomes.Add(magnet); }
public bool isInOurGroup(MagnetPattern other) { if (other.id == id) { return(true); } for (int i = 0; i < leaded.Count; i++) { if (leaded[i].id == other.id) { return(true); } } return(false); }
IEnumerator CheckChromosomes() { for (int i = 0; i < chromosomes.Count; i++) { MagnetPattern chromosome = chromosomes[i]; if (chromosome.isAttached || chromosome.isFull) { chromosomes.RemoveAt(i); i--; } } yield return(new WaitForSeconds(1f)); StartCoroutine("CheckChromosomes"); }
public void reachingOther(GameObject other, Detector detector) { MagnetPattern otherMagnet = other.gameObject.GetComponent <MagnetPattern>(); if (!isAttached) { if (!otherMagnet.isAttached && (leadCapacity < otherMagnet.leadCapacity || (otherMagnet.isLeading && leadCapacity == otherMagnet.leadCapacity))) { JoiningPattern join = gameObject.GetComponent <JoiningPattern>(); join.enabled = true; if (otherMagnet.leaded.Count > 0) { int count = otherMagnet.leaded.Count; MagnetPattern lastLeaded = otherMagnet.leaded[count - (Random.Range(1, 1))]; if (lastLeaded) { join.MakeJoin(anchors, lastLeaded.anchors, lastLeaded.gameObject.rigidbody2D, lastLeaded.transform); } } else { join.MakeJoin(anchors, otherMagnet.anchors, other.gameObject.rigidbody2D, other.transform); } isLeading = false; leader = otherMagnet; //detector.enabled = false; StartCoroutine("Attach"); } else if (!otherMagnet.isAttached) { isLeading = true; isAttached = false; } } else { // if(!leader.isInOurGroup(otherMagnet)){ // //leader.reachingOther(other, detector); // } } }
IEnumerator FindTarget() { float distance = 0; foreach (MagnetPattern chromosome in otherChromosomes) { if (chromosome) { float chromosomeDistance = Vector3.Distance(transform.position, chromosome.gameObject.transform.position); if (chromosome.id != id && (distance == 0 || distance > chromosomeDistance) && !chromosome.isFull) { distance = chromosomeDistance; targetChromosome = chromosome; continue; } } } yield return(new WaitForSeconds(cooldown)); StartCoroutine("FindTarget"); }
public void newChromosome(MagnetPattern chromosome) { otherChromosomes.Add(chromosome); }
// Use this for initialization void Start() { camera = GameObject.FindGameObjectWithTag("TrueMainCamera"); magnet = gameObject.GetComponent <MagnetPattern>(); }