Exemplo n.º 1
0
    void FixedUpdate()
    {
        if (player != null)
        {
            GameObject player_go = GameObject.FindGameObjectWithTag("Player");
            movement   movm      = player_go.GetComponent <movement> ();
            if (movm.isStarted())
            {
                Vector3 pos = transform.position;
                pos.x += prevSpeed * Time.deltaTime;
                transform.position = pos;

                if (prevSpeed < player.GetComponent <Rigidbody2D>().velocity.x + 2f)
                {
                    prevSpeed = player.GetComponent <Rigidbody2D>().velocity.x - 1f;
                    if (prevSpeed < 2f)
                    {
                        prevSpeed = 2f;
                    }
                }
                if (player.GetComponent <Rigidbody2D>().position.x - transform.position.x > -1)
                {
                    prevSpeed += 50f * Time.deltaTime;
                }
            }
            else
            {
                prevSpeed = 0;
            }
        }
    }