Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        ball     = GameObject.FindGameObjectWithTag("ball");
        ballInfo = ball.GetComponent <BalleController>();
        agent    = GetComponent <NavMeshAgent>();

        initializeMyGameZone();
        myZoneCenter = transform.position;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (ball == null)
        {
            ball     = GameObject.FindGameObjectWithTag("ball");
            ballInfo = ball.GetComponent <BalleController>();
        }
        Vector3 ballPosition = ball.transform.position;

        ballPosition.y = 0;
        if (ballInMyZone(ballPosition))
        {
            if (ballOnMyLeftSide(ballPosition))
            {
                float distanceToBall = Vector3.Distance(transform.position, ballPosition);
                float speed          = distanceToBall * 10;
                if (speed <= 10)
                {
                    speed = 10;
                }
                agent.speed = speed;
                agent.SetDestination(ballPosition - ball.transform.up * 2);
            }
            else
            {
                goToRightSide(ballPosition);
            }
        }
        else
        {
            if (transform.position != myZoneCenter)
            {
                goBackToCenter();
            }
        }
    }