void FixedUpdate()
 {
     if (trigger.isActive() && (transform.position.y < originalY))
     {
         moveY(transform.position.y + speed);
     }
     if (!trigger.isActive() && (transform.position.y > (originalY - height)))
     {
         moveY(transform.position.y - speed);
     }
 }
Esempio n. 2
0
 void Update()
 {
     if (!active && trigger.isActive())
     {
         active = true;
         InvokeRepeating("dropObject", 0f, interval);
     }
     if (active && !trigger.isActive())
     {
         active = false;
         CancelInvoke();
     }
 }
Esempio n. 3
0
    void FixedUpdate()
    {
        if (trigger.isActive())
        {
            //
            // Move right and left
            //
            float moveHorizontal = target.transform.position.x > transform.position.x ? 1f : -1f;
            rb.AddForce(new Vector2(moveHorizontal * speed, 0f), ForceMode2D.Impulse);
            rb.AddForce(-new Vector2(rb.velocity.x, 0) * slow);

            //
            // Jump
            //
            float moveVertical = !isPlateformAhead(moveHorizontal) ? 1f : 0f;

            if (rb.velocity.y == 0f) // If the character is on the ground
            {
                rb.AddForce(new Vector2(0f, moveVertical) * jump, ForceMode2D.Impulse);
            }
        }
    }