コード例 #1
0
    bool ZoomUpdate()
    {
        zoomTimeElapsed     += Time.deltaTime;
        zoomIntervalElapsed += Time.deltaTime;
        if (shotElapsed >= shotTime)
        {
            shotElapsed = 0f;
            zooms[Random.Range(0, zooms.Count - 1)].entity.GetComponent <Enemy>().Shoot();
        }

        for (int i = 0; i < zooms.Count; i++)
        {
            zooms[i] = Zoom(zooms[i]);
        }
        zooms.RemoveAll(c => c.zoomStage > 3);
        if (zoomTimeElapsed >= zoomTime)
        {
            return(zooms.Count == 0);
        }

        if (zoomIntervalElapsed >= zoomInterval)
        {
            zoomIntervalElapsed = 0f;

            Transform t;
            bool      contains;
            int       itrs = 0;
            do
            {
                t        = Enemy.enemies[Random.Range(0, Enemy.enemies.Count - 1)].transform;
                contains = false;
                foreach (ZoomHolder z in zooms)
                {
                    if (++itrs > Enemy.enemies.Count)
                    {
                        return(false);
                    }
                    if (t == z.entity)
                    {
                        contains = true;
                        break;
                    }
                }
            } while (contains);

            ZoomHolder zoom = new ZoomHolder();
            zoom.Initialize(t, FindObjectOfType <Player>().transform.position);
            zooms.Add(zoom);
        }
        return(false);
    }
コード例 #2
0
    ZoomHolder Zoom(ZoomHolder z)
    {
        if (z.zoomStage > 3)
        {
            Debug.Log("Invalid");
        }
        else if (z.zoomStage > 2)
        {
            z.entity.LookAt(z.origPos);
            z.entity.position += z.entity.forward * zoomSpeed * Time.deltaTime;
            if (Vector3.Distance(z.entity.position, z.origPos) <= zoomEpsilon)
            {
                z.entity.rotation = Quaternion.identity;
                z.zoomStage       = 4;
            }
        }
        else if (z.zoomStage > 1)
        {
            z.waitElapsed += Time.deltaTime;
            if (z.waitElapsed >= zoomWait)
            {
                z.zoomStage = 3;
            }
        }
        else
        {
            z.entity.LookAt(z.center);
            z.entity.position += z.entity.forward * zoomSpeed * Time.deltaTime;
            if (Vector3.Distance(z.entity.position, z.center) <= zoomRadius + zoomEpsilon)
            {
                z.zoomStage = 2;
            }
        }

        return(z);
    }