Exemplo n.º 1
0
    protected override void CreateBall()
    {
        if (BallInstance != null)
        {
            Destroy(BallInstance);
        }
        BallInstance = Instantiate(BallPrefab);
        float size = Random.Range(MinSize, MaxSize);

        BallInstance.transform.localScale = new Vector3(size, size, 1);
        Rigidbody2D rb        = BallInstance.GetComponent <Rigidbody2D>();
        Vector2     direction = Random.insideUnitCircle.normalized;

        if (Mathf.Abs(direction.y) < Mathf.Abs(direction.x))
        {
            direction = Vector2.Perpendicular(direction);
        }
        float velocity = Random.Range(MinVelocity, MaxVelocity);

        rb.velocity = direction * velocity;
        SkinObject selectedSkin = SkinsController.Instance.GetSelectedSkin();

        if (selectedSkin != null)
        {
            SpriteRenderer renderer = BallInstance.GetComponent <SpriteRenderer>();
            renderer.color = selectedSkin.Colour;
        }
    }
Exemplo n.º 2
0
        void CustomActivity(bool firstTimeCalled)
        {
            if (!GameIsActive)
            {
                return;
            }

            var cursorX = GuiManager.Cursor.WorldXAt(0);
            var cursorY = GuiManager.Cursor.WorldYAt(0);

            var cursorPosition = new Vector3(cursorX, cursorY, 0);
            var difference     = cursorPosition - PaddleInstance.Position;

            if (Math.Abs(difference.Length()) > .00001f)
            {
                PaddleInstance.Velocity = difference * PaddleSpeedMultiplier;
            }


            var direction = (BallInstance.Y - AIPaddle.Y);

            if (direction > 0.00001f)
            {
                AIPaddle.YVelocity = maxAISpeed;
            }
            else if (direction < -0.00001f)
            {
                AIPaddle.YVelocity = -maxAISpeed;
            }
            else
            {
                AIPaddle.YVelocity = 0;
            }

            BallInstance.CollideAgainstBounce(PaddleInstance, 0, 1, 1);
            BallInstance.CollideAgainstBounce(AIPaddle, 0, 1, 1);
            BallInstance.CollideAgainstBounce(Boundaries, 0, 1, 1);

            if (BallInstance.CollideAgainst(GoalInstance))
            {
                TriggerWinCondition();
            }
        }