Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        var x = 0;

        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            x = -1;
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            x = 1;
        }

        if (!movementEnabled)
        {
            x = 0;
        }

        var totalGravity = BlackHole.AccelerationAtPoint(transform.position);
        var newVelocity  = rg.velocity + Vector2.Dot(totalGravity, transform.right) * (Vector2)transform.right * Time.deltaTime;
        var angle        = (Mathf.Atan2(newVelocity.y, newVelocity.x) - Mathf.PI * 0.5f) + x * rotationSpeed * Time.deltaTime;

        transform.rotation = Quaternion.Euler(0, 0, angle * Mathf.Rad2Deg);
        rg.velocity        = (Vector2)transform.up * (speed + currentBoost);

        if (Time.time - boostTime > boostDuration)
        {
            currentBoost = Mathf.Lerp(currentBoost, 0, 4 * Time.deltaTime);
        }

        if (Input.GetKeyDown(KeyCode.Space) && boostButton.interactable)
        {
            Jump();
        }

        if (Time.time - boostTime > boostCooldown)
        {
            boostIcon.sprite         = boostActive;
            boostButton.interactable = true;
        }
        else
        {
            boostIcon.sprite         = boostInactive;
            boostButton.interactable = false;
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            var go = GameObject.Instantiate(duck, transform.position, Quaternion.identity) as GameObject;
            go.GetComponent <Rigidbody2D>().velocity = transform.up * duckSpeed;
        }
    }
Beispiel #2
0
    void Update()
    {
        var rg = GetComponent <Rigidbody2D>();

        rg.velocity += BlackHole.AccelerationAtPoint(transform.position) * Time.deltaTime;
    }