Exemplo n.º 1
0
    void HitTarget()
    {
        Debug.Log("Hit Target");

        //Instantly destory target
        DNABott enemycurr = target.gameObject.GetComponent <DNABott>();

        if (enemycurr != null)
        {
            enemycurr.TakeDamage(damage);
        }
        else
        {
            Destroy(gameObject);
        }
    }
    private void Breed(GameObject gameObject1, GameObject gameObject2)
    {
        DNABott    dna1 = gameObject1.GetComponent <DNABott>();
        DNABott    dna2 = gameObject2.GetComponent <DNABott>();
        GameObject offspring;

        if (Random.Range(0, 1000) > 100f)
        {
            if (Random.Range(0, 10) <= 5f)
            {
                Debug.Log("Called1");
                Vector3 pos = new Vector3(dna1.spwanPoint.position.x + Random.Range(-0.5f, 0.5f), 0f, dna1.spwanPoint.position.z + Random.Range(-0.5f, 0.5f));
                offspring = Instantiate(personPrefab, pos, Quaternion.identity);
                offspring.GetComponent <DNABott>().spwanPoint = dna1.spwanPoint;
                population.Add(offspring);
            }
            else
            {
                Debug.Log("Called2");
                Vector3 pos = new Vector3(dna2.spwanPoint.position.x + Random.Range(-0.5f, 0.5f), 0f, dna2.spwanPoint.position.z + Random.Range(-0.5f, 0.5f));
                offspring = Instantiate(personPrefab, pos, Quaternion.identity);
                offspring.GetComponent <DNABott>().spwanPoint = dna2.spwanPoint;
                population.Add(offspring);
            }
        }
        else
        {
            if (Random.Range(1, 3) == 1)
            {
                Vector3 pos = new Vector3(spwanPoint1.position.x + Random.Range(-0.5f, 0.5f), 0f, spwanPoint1.position.z + Random.Range(-0.5f, 0.5f));
                offspring = Instantiate(personPrefab, pos, Quaternion.identity);
                offspring.GetComponent <DNABott>().spwanPoint = spwanPoint1;
                population.Add(offspring);
            }
            else
            {
                Vector3 pos = new Vector3(spwanPoint2.position.x + Random.Range(-0.5f, 0.5f), 0f, spwanPoint2.position.z + Random.Range(-0.5f, 0.5f));
                offspring = Instantiate(personPrefab, pos, Quaternion.identity);
                offspring.GetComponent <DNABott>().spwanPoint = spwanPoint2;
                population.Add(offspring);
            }
        }
    }