示例#1
0
    void Update()
    {
        ZoneWall.transform.localScale = new Vector3((Radius * 0.01f), 1, (Radius * 0.01f));
        if (Shrinking)
        {
            // we need a new center point (that is within the bounds of the current zone)
            if (!newCenterObtained)
            {
                centerPoint          = NewCenterPoint(ZoneWall.transform.position, Radius, shrinkRadius);
                distanceToMoveCenter = Vector3.Distance(ZoneWall.transform.position, centerPoint);                 //this is used in the Lerp (below)
                newCenterObtained    = (centerPoint != new Vector3(0, -100, 0));
            }

            //Debug.Log("New Center Point is " + centerPoint);

            // move the center point, over time
            transform.position = Vector3.MoveTowards(transform.position, centerPoint, (distanceToMoveCenter / timeToShrink) * Time.deltaTime);
            // shrink the zone diameter, over time
            Radius = Mathf.MoveTowards(Radius, shrinkRadius, (shrinkRadius / timeToShrink) * Time.deltaTime);
            //move ZoneWall towards new centerpoint
            ZoneWall.transform.position = Vector3.MoveTowards(ZoneWall.transform.position, new Vector3(centerPoint.x, ZoneWall.transform.position.y, centerPoint.z), (distanceToMoveCenter / timeToShrink) * Time.deltaTime);
            // shrink circle projector
            safeZone_Circle_Projector.orthographicSize = Radius;

            circle.Draw(Segments, Radius, Radius);

            // MoveTowards will continue infinitum, so we must test that we have gotten close enough to be DONE
            if (1 > (Radius - shrinkRadius))
            {
                timePassed        = Time.deltaTime;
                Shrinking         = false;
                newCenterObtained = false;
            }
        }
        else
        {
            timePassed += Time.deltaTime;             // increment clock time
        }

        // have we passed the next threshold for time delay?
        if (((int)timePassed) > ZoneTimes[zoneTimesIndex])
        {
            shrinkRadius = Radius - (float)(Radius * (ZoneRadiusFactor * 0.01)); //use the ZoneRadiusFactor as a percentage
            Shrinking    = true;
            timePassed   = Time.deltaTime;                                       //reset the time so other operations are halted.
            NextZoneTime();
        }

        // COUNT DOWN
        if (timePassed > (ZoneTimes[zoneTimesIndex] - countdownPrecall))            // we need to begin counting down
        {
            if (ZoneTimes[zoneTimesIndex] - (int)timePassed != count)
            {
                count = Mathf.Clamp(ZoneTimes[zoneTimesIndex] - (int)timePassed, 1, 1000);                   // this ensures our value never falls below zero

                //FILL IN APPROPRIATE UI CALLS HERE FOR THE COUNTDOWN
                //Debug.Log("Shrinking in " + count + " seconds.");
            }
        }
    }
    void Update()
    {
        if (Shrinking)
        {
            var ZoneWallPosition = ZoneWall.transform.position; // no need to call this so many times in the Update
                                                                // we need a new center point (that is within the bounds of the current zone)
            if (!newCenterObtained)
            {
                centerPoint          = NewCenterPoint(ZoneWallPosition, XRadius, shrinkRadius);
                distanceToMoveCenter = Vector3.Distance(ZoneWallPosition, centerPoint); //this is used in the Lerp (below)
                newCenterObtained    = (centerPoint != new Vector3(0, -100, 0));
            }

            // move the center point, over time
            transform.position = Vector3.MoveTowards(transform.position, centerPoint, (distanceToMoveCenter / timeToShrink) * Time.deltaTime);
            // shrink the zone diameter, over time
            XRadius = Mathf.MoveTowards(XRadius, shrinkRadius, (shrinkRadius / timeToShrink) * Time.deltaTime);
            ZoneWall.transform.localScale = new Vector3((XRadius * 0.01f), ZoneWall.transform.localScale.y, (XRadius * 0.01f));
            ZoneWall.transform.position   = new Vector3(transform.position.x, ZoneWallPosition.y, transform.position.z);

            circle.Draw(Segments, XRadius, XRadius);

            // MoveTowards will continue infinitum, so we must test that we have gotten close enough to be DONE
            if (1 > (XRadius - shrinkRadius))
            {
                timePassed        = Time.deltaTime;
                Shrinking         = false;
                newCenterObtained = false;
            }
        }
        else
        {
            timePassed += Time.deltaTime; // increment clock time
        }

        // have we passed the next threshold for time delay?
        if (((int)timePassed) > ZoneTimes[zoneTimesIndex])
        {
            shrinkRadius = ShrinkCircle((float)(XRadius * (ZoneRadiusFactor * 0.01)))[1]; //use the ZoneRadiusFactor as a percentage
            Shrinking    = true;
            timePassed   = Time.deltaTime;                                                //reset the time so other operations are halted.
            if (NextZoneTime() < 0)
            {
                Shrinking = false; //we have reached the end of our list
            }
        }

        // COUNT DOWN
        if (timePassed > (ZoneTimes[zoneTimesIndex] - countdownPrecall))
        {  // we need to begin counting down
            if (ZoneTimes[zoneTimesIndex] - (int)timePassed != count)
            {
                count = Mathf.Clamp(ZoneTimes[zoneTimesIndex] - (int)timePassed, 1, 1000);  // this ensures our value never falls below zero

                //FILL IN APPROPRIATE UI CALLS HERE FOR THE COUNTDOWN
                Debug.Log("Shrinking in " + count + " seconds.");
            }
        }
    }
示例#3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Shrinking = true;
     }
     if (Shrinking)
     {
         XRadius = Mathf.Lerp(XRadius, ShrinkCircle(XRadius)[0], Time.deltaTime * 0.5f);
         circle.Draw(Segments, XRadius, XRadius);
     }
     ZoneWall.transform.localScale = new Vector3((XRadius * 0.01f), 1, (XRadius * 0.01f));
     //Debug.Log (XRadius);//print test
 }