Beispiel #1
0
 void OnTriggerEnter(Collider target)
 {
     if (target.tag == "Player")
     {
         CombatFlockBehaviour kill = gameObject.GetComponentInParent <CombatFlockBehaviour>();
         kill.destroy();
         this.gameObject.SetActive(false);
     }
 }
    void ApplyRules()
    {
        List <GameObject> gos;

        gos = GameObject.Find("CombatFlock(Clone)").GetComponent <Flock>().allUnits;
        Vector3 goalPos = flocking.goalPos;
        Vector3 vcentre = Vector3.zero;
        Vector3 vavoid  = Vector3.zero;
        float   dist;

        int groupSize = 0;

        foreach (GameObject go in gos)
        {
            if (go != this.gameObject)
            {
                dist = Vector3.Distance(go.transform.position, this.transform.position);
                if (dist <= neighbourDistance)
                {
                    vcentre += go.transform.position;
                    groupSize++;
                    if (dist < 1.0f)
                    {
                        vavoid = vavoid + (this.transform.position - go.transform.position);
                    }
                    CombatFlockBehaviour anotherFlock = go.GetComponent <CombatFlockBehaviour>();
                }
            }
        }

        if (groupSize > 0)
        {
            vcentre = vcentre / groupSize + (goalPos - this.transform.position);

            Vector3 direction = (vcentre + vavoid) - transform.position;
            if (direction != Vector3.zero)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
            }
        }
    }