observe() public method

public observe ( GameObject a, GameObject b ) : void
a GameObject
b GameObject
return void
Ejemplo n.º 1
0
    void most_similar_creature()
    {
        targetCrt = null;                               // reference to the script of the closest creature
        GameObject target     = null;
        GameObject c          = null;                   // current collider being looked at
        float      similarity = Mathf.Infinity;
        float      curr_similarity;

        cs = Physics.OverlapSphere(_t.position, (float)los);


        if (cs.Length == 0)
        {
            target = null;
            return;
        }

        foreach (Collider col in cs)
        {
            c = (GameObject)col.transform.gameObject;
            if (c && c.gameObject.name == "root" && c != crt.root.gameObject)
            {
                other_crt       = c.transform.parent.GetComponent <Creature>();
                curr_similarity = GeneticsUtils.similar_colour(crt.chromosome, other_crt.chromosome);

                if (curr_similarity < similarity)
                {
                    target     = c.transform.parent.gameObject;
                    similarity = curr_similarity;
                }

                Vector3 diff = c.transform.position - _t.position;
                if (diff.magnitude < (float)crt_mate_range)
                {
                    other_crt = c.transform.parent.GetComponent <Creature>();
                    Genitalia other_genital = other_crt.genital.GetComponent <Genitalia>();
                    if (crt.state == Creature.State.persuing_mate || other_crt.state == Creature.State.persuing_mate)
                    {
                        co.observe(crt.genital.gameObject, other_genital.gameObject);
                        other_crt.state = Creature.State.mating;
                        crt.state       = Creature.State.mating;
                    }
                    similarity = curr_similarity;
                }
            }

            distance_to_goal = 0F;
            goal             = null;
            if (target)
            {
                targetCrt        = target.GetComponent <Creature>();
                goal             = targetCrt.root;
                distance_to_goal = distanceToGoal();
            }
        }
    }