Exemplo n.º 1
0
    private void OnUpdate()
    {
        if (Input.IsKeyPressed(KeyCode.W))
        {
            rb.AddImpulse(new Vector3(1, 0, 0));
            rb.AddTorque(new Vector3(0, 0, -5));
        }

        if (Input.IsKeyPressed(KeyCode.S))
        {
            rb.AddImpulse(new Vector3(-1, 0, 0));
            rb.AddTorque(new Vector3(0, 0, 5));
        }

        if (Input.IsKeyPressed(KeyCode.D))
        {
            rb.AddTorque(new Vector3(2, 0, 0));
            rb.AddImpulse(new Vector3(0, 0, 1));
        }

        if (Input.IsKeyPressed(KeyCode.A))
        {
            rb.AddTorque(new Vector3(-2, 0, 0));
            rb.AddImpulse(new Vector3(0, 0, -1));
        }

        if (Input.IsKeyPressed(KeyCode.Space))
        {
            rb.AddImpulse(new Vector3(0, 10, 0));
        }
    }
Exemplo n.º 2
0
    void SpawnBall()
    {
        Prefab pref   = null;
        Random random = new System.Random();
        int    num    = random.Next(0, 3);

        switch (num)
        {
        case 0:
        {
            pref = BallPref;
            break;
        }

        case 1:
        {
            pref = BallPref2;
            break;
        }

        case 2:
        {
            pref = BallPref3;
            break;
        }
        }

        Actor ball = pref.Instantiate(new Vector3(GetRandomNumber(spawn_point.Position.X, spawn_point.Position.X + 50),
                                                  spawn_point.Position.Y, GetRandomNumber(spawn_point.Position.Z, spawn_point.Position.Z + 50)));

        RigidBodyComponent rb = new RigidBodyComponent();

        if (ball.GetComponent <RigidBodyComponent>(ref rb))
        {
            rb.AddImpulse(new Vector3(0, -40.0f, 0));
        }
    }