Racket.Update C# (CSharp) Method

Update() public method

public Update ( ) : void
return void
    public void Update()
    {
        if (isTop)
        {
            isValid = (pongpector.GetAnother(-1) == null);
        }
        else
        {
            isValid = (pongpector.GetAnother(1) == null);
        }
        if (!isValid)
        {
            return;
        }
        var rx = Mathf.Clamp(x * pongpector.width, width / 2 + 1, pongpector.width - width / 2 - 1);
        texture.DrawFilledRectangle(new Rect
            (rx - width / 2, y - height / 2, width, height), Color.blue);
    }

Usage Example

示例#1
0
    public void UpdateFrame()
    {
        if (texture == null || topRacket == null || bottomRacket == null)
        {
            Start();
        }
        texture.DrawFilledRectangle(new Rect(0, 0, width, height), Color.clear);
        var wallColor = Color.blue;

        if (missCount > 0)
        {
            wallColor = Color.red;
            missCount--;
        }
        texture.DrawFilledRectangle(new Rect(0, 0, wallWidth, height), wallColor);
        texture.DrawFilledRectangle(new Rect(width - wallWidth, 0, wallWidth, height), wallColor);
        balls       = balls.FindAll((b) => b.Update());
        topRacket.x = topRacketX;
        topRacket.Update();
        isTopRacketValid = topRacket.isValid;
        bottomRacket.x   = bottomRacketX;
        bottomRacket.Update();
        isBottomRacketValid = bottomRacket.isValid;
        texture.Apply();
        Status status = null;

        try
        {
            status = gameObject.GetComponent <Status>() as Status;
        }
        catch (MissingReferenceException) { }
        if (status != null)
        {
            if (status.ticks % 500 == 0 && !status.isGameover)
            {
                AddBall(Mathf.Sqrt(1 + status.ticks * 0.0003f));
            }
            if (status.isRestarting || status.isGameover)
            {
                balls.Clear();
                if (status.isRestarting)
                {
                    AddBall();
                }
            }
            var bc = balls.Count;
            if (isTopRacketValid)
            {
                status.tmpBallCount = bc;
            }
            else
            {
                status.tmpBallCount += bc;
            }
            if (isBottomRacketValid)
            {
                status.ballCount = status.tmpBallCount;
                status.ticks++;
                if (status.isRestarting)
                {
                    status.isRestarting = false;
                }
            }
        }
    }