Esempio n. 1
0
    void moveBallToClosest()
    {
        Vector3 position = ball.transform.position;

        o1Closest = getClosest(o1List);
        o2Closest = getClosest(o2List);
        var distance1 = (o1Closest.transform.position - position).magnitude;
        var distance2 = (o2Closest.transform.position - position).magnitude;

        if (ballCont.getVel().magnitude > 3)
        {
            return;
        }
        if (distance1 < distance2 && distance1 < 2.1f)
        {
            ball.transform.position = new Vector3(o1Closest.transform.position.x - 1.3f, o1Closest.transform.position.y, -0.1f);
            whoHasTheBall           = Takım.RED;
            o1Closest.GetComponent <Rigidbody2D>().velocity = new Vector3(0, 0, 0);
        }
        else if (distance2 < 2.1f)
        {
            ball.transform.position = new Vector3(o2Closest.transform.position.x + 1.3f, o2Closest.transform.position.y, -0.1f);
            whoHasTheBall           = Takım.BLUE;
            o2Closest.GetComponent <Rigidbody2D>().velocity = new Vector3(0, 0, 0);
        }
        else
        {
            //whoHasTheBall=Takım.NONE;
        }
    }
    void setPostY(float d_y)
    {
        float speed = Math.Abs(ballCont.getVel().x);
        var   pos   = transform.position;

        pos.y = d_y;
        transform.position = Vector3.Lerp(this.transform.position, pos, speed / 120);
    }