Ejemplo n.º 1
0
    public void StopPosReceiver(Transform virusTrans)
    {
        VirusPosReceiver pr = GetComponent <VirusPosReceiver> ();

        if (pr)
        {
            pr.enabled = false;
        }
    }
Ejemplo n.º 2
0
    /* StartMovement:
     * 1. start the enemy from chasing the target again
     * 2. reset the linear/angular drag
     */
    void StartMovement(Transform objTrans)
    {
        ChaseTarget ct = this.transform.GetComponent <ChaseTarget> ();

        if (ct != null)
        {
            ct.enabled = true;
        }
        VirusPosReceiver pr = this.transform.GetComponent <VirusPosReceiver> ();

        if (pr != null)
        {
            pr.enabled = true;
        }

        if (myRigidbody2D != null)
        {
            // increase my drag
            myRigidbody2D.angularDrag = oldDrag;
            myRigidbody2D.drag        = oldAngularDrag;
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (fov)
        {
            facing = fov.facing;
        }


        virusList.Clear();
        // get all childs which is a virus
        foreach (Transform child in transform)
        {
            // does if have a objectIdentity and the identity is virus?
            ObjectIdentity oi = child.GetComponentInChildren <ObjectIdentity> ();
            if (oi && oi.objType == ObjectType.Virus)
            {
                // append it to the virus list
                // only append idle and controlling
                VirusStateControl sc = oi.transform.GetComponent <VirusStateControl> ();
                ControlStatus     cs = oi.transform.GetComponent <ControlStatus> ();
                bool controlling     = (cs.controller != Controller.None);
                bool nowIdle         = (sc.virusState == VirusStateControl.VirusState.Idle);

                if (sc && controlling && nowIdle)
                {
                    virusList.Add(oi.transform);
                }
            }
        }
        virusCount = virusList.Count;
        if (virusCount == 0)
        {
            return;
        }
        // set the facing vector
        if (facing == Vector3.zero)
        {
            facing = transform.up;
        }
        facing.Normalize();

        // set the pos and rotation for each enemy
        float startAngle = 0f;

        if (virusCount != 1)
        {
            startAngle = -intervalAngle * (virusCount - 1) / 2.0f;
        }

        // initialize rotCursor
        Quaternion rotCursor = Quaternion.FromToRotation(Vector3.up, facing);

        rotCursor *= Quaternion.Euler(0f, 0f, startAngle);

        //Debug.Log (rotCursor.eulerAngles);

        foreach (Transform virus in virusList)
        {
            VirusPosReceiver receiver = virus.GetComponent <VirusPosReceiver> ();
            if (receiver)
            {
                // set the desiredRotation
                receiver.desiredRot = rotCursor;
                // set the desiredPosition
                Vector3 dirToVirus = rotCursor * Vector3.up;
                dirToVirus.Normalize();
                Vector3 newPos = transform.position + dirToVirus * spreadRadius;
                //Debug.Log (newPos);
                receiver.desiredPos = newPos;



                // set child virus speed
                receiver.moveSpeed = moveSpeed;
                receiver.rotSpeed  = rotSpeed;
            }

            rotCursor = Quaternion.AngleAxis(intervalAngle, Vector3.forward) * rotCursor;
        }
    }