Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (following == false)
        {
            m_animator.SetBool("Followig", false);
            m_animator.SetBool("moving", true);
            move.max_mov_velocity = 1.5f;
            if (calc == false)
            {
                newPosition   = Random.insideUnitSphere;
                newPosition  *= radius * 15;
                newPosition  += transform.position;
                newPosition.y = transform.position.y;
                distance      = (new Vector3(newPosition.x, newPosition.y, newPosition.z) - transform.position).magnitude;
                NavMeshPath policePath = new NavMeshPath();
                police.CalculatePath(newPosition, policePath);
                if (policePath.corners.Length >= 1)
                {
                    Vector3[] pathCorners = new Vector3[policePath.corners.Length];
                    policePath.corners.CopyTo(pathCorners, 0);
                    seek.SetPathCorners(pathCorners);
                    calc = true;
                }
            }


            float distance2 = (newPosition - transform.position).magnitude;
            if (distance2 <= 3.0f)
            {
                calc = false;
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
        float   distance = path.GetDistance();
        Vector3 diff     = desiredPoint - transform.position;

        if (diff.magnitude < 1)
        {
            if (currentRatio >= 1)
            {
                currentRatio = 0;
            }
            else
            {
                currentRatio += ratio;
            }
            desiredPoint = path.CalcPositionByDistanceRatio(currentRatio);
            distance     = (new Vector3(desiredPoint.x, desiredPoint.y, desiredPoint.z) - move.transform.position).magnitude;
            NavMeshPath nerdPath = new NavMeshPath();
            agent.police.CalculatePath(desiredPoint, nerdPath);
            pathCorners = new Vector3[nerdPath.corners.Length];

            nerdPath.corners.CopyTo(pathCorners, 0);
        }
        seek.SetPathCorners(pathCorners);
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (RedList != null)
        {
            object[] obj = GameObject.FindSceneObjectsOfType(typeof(GameObject));
            foreach (object o in obj)
            {
                GameObject g = (GameObject)o;

                if (g.tag == "red")
                {
                    if (RedList.Contains(g) == false)
                    {
                        RedList.Add(g);
                    }
                }

                if (g.tag == "Pay2")
                {
                    pay = g;
                }
            }
        }


        if (RedList != null)
        {
            goingPay = true;
            if (bought == false)
            {
                bought   = true;
                randNumb = Random.Range(0, RedList.Count - 1);

                distance = (RedList[randNumb].transform.position - transform.position).magnitude;
                NavMeshPath nerdPath = new NavMeshPath();
                m_agent.CalculatePath(RedList[randNumb].transform.position, nerdPath);
                Vector3[] pathCorners = new Vector3[nerdPath.corners.Length];
                nerdPath.corners.CopyTo(pathCorners, 0);
                seek.SetPathCorners(pathCorners);
            }
            else
            {
                float distance2 = (RedList[randNumb].transform.position - transform.position).magnitude;
                if (distance2 <= 1.5f)
                {
                    animator.SetBool("Buy", true);
                    animatorGame.SetTrigger("Create");
                    animatorGame.SetBool("HasGame", true);
                    BuyTimer -= Time.deltaTime;
                    if (BuyTimer <= 0.1f)
                    {
                        RedList.Clear();
                        RedList = null;

                        BuyTimer = 5.0f;
                    }
                }
            }
        }
        else
        {
            if (goingPay == true)
            {
                goingPay = false;

                distance = (pay.transform.position - transform.position).magnitude;
                NavMeshPath goHome = new NavMeshPath();
                m_agent.CalculatePath(pay.transform.position, goHome);
                Vector3[] goHomePath = new Vector3[goHome.corners.Length];
                goHome.corners.CopyTo(goHomePath, 0);
                seek.SetPathCorners(goHomePath);
            }
            else
            {
                float distance3 = (pay.transform.position - transform.position).magnitude;
                if (distance3 > 1.5f)
                {
                    animator.SetBool("Buy", false);
                    animatorGame.SetTrigger("Destroy");
                    animatorGame.SetBool("HasGame", false);
                }
                else
                {
                    animator.SetBool("Buy", true);
                    BuyTimer -= Time.deltaTime;
                    if (BuyTimer <= 0.1f)
                    {
                        Destroy(this.gameObject);
                        BuyTimer = 5.0f;
                    }
                }
            }
        }
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        object[] obj = GameObject.FindSceneObjectsOfType(typeof(GameObject));
        foreach (object o in obj)
        {
            GameObject g = (GameObject)o;
            if (g.tag == "Rubish")
            {
                if (CleanerList.Contains(g) == false)
                {
                    CleanerList.Add(g);
                }
            }
        }

        if (CleanerList.Count != 0)
        {
            goingHome = false;
            if (thisOne == null)
            {
                for (int i = 0; i < CleanerList.Count; i++)
                {
                    float otherdist = (CleanerList [i].transform.position - transform.position).magnitude;
                    if (otherdist <= distance)
                    {
                        distance = otherdist;
                        thisOne  = CleanerList [i];
                        NavMeshPath rubbishPath = new NavMeshPath();
                        agent.CalculatePath(thisOne.transform.position, rubbishPath);
                        Vector3[] pathCorners = new Vector3[rubbishPath.corners.Length];
                        rubbishPath.corners.CopyTo(pathCorners, 0);
                        seek.SetPathCorners(pathCorners);
                    }
                }
            }
            else
            {
                float distance2 = (thisOne.transform.position - transform.position).magnitude;

                if (distance2 > 1.5f)
                {
                    m_animator.SetBool("movement", true);
                    RAnimator.SetTrigger("Destroy");
                    m_animator.SetBool("clean", false);
                }
                else
                {
                    m_animator.SetBool("movement", false);
                    m_animator.SetBool("clean", true);
                    RAnimator.SetTrigger("Create");

                    cleanTimer -= Time.deltaTime;
                    if (cleanTimer <= 0.1f)
                    {
                        CleanerList.Remove(thisOne);
                        Destroy(thisOne);
                        thisOne    = null;
                        distance   = 2000;
                        cleanTimer = 5.0f;
                    }
                }
            }
        }
        else
        {
            if (goingHome == false)
            {
                NavMeshPath rubbishPath = new NavMeshPath();
                agent.CalculatePath(cleanerhome, rubbishPath);
                Vector3[] pathCorners = new Vector3[rubbishPath.corners.Length];
                rubbishPath.corners.CopyTo(pathCorners, 0);
                seek.SetPathCorners(pathCorners);
                goingHome = true;
            }

            m_animator.SetBool("clean", false);
            RAnimator.SetTrigger("Destroy");

            float distance3 = (cleanerhome - transform.position).magnitude;
            if (distance3 > 1.5f)
            {
                m_animator.SetBool("movement", true);
            }
            else
            {
                m_animator.SetBool("movement", false);
                distance = 2000;
            }
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (StealList != null)
        {
            object[] obj = GameObject.FindSceneObjectsOfType(typeof(GameObject));
            foreach (object o in obj)
            {
                GameObject g = (GameObject)o;

                if (g.tag == "red" || g.tag == "green" || g.tag == "blue")
                {
                    if (StealList.Contains(g) == false)
                    {
                        StealList.Add(g);
                    }
                }
                else if (g.tag == "Leave")
                {
                    home = g;
                }
            }
        }

        if (StealList != null)
        {
            if (steal == false)
            {
                steal    = true;
                randNumb = Random.Range(0, StealList.Count - 1);

                distance = (StealList[randNumb].transform.position - transform.position).magnitude;
                NavMeshPath nerdPath = new NavMeshPath();
                m_robber.CalculatePath(StealList[randNumb].transform.position, nerdPath);
                Vector3[] pathCorners = new Vector3[nerdPath.corners.Length];
                nerdPath.corners.CopyTo(pathCorners, 0);
                seek.SetPathCorners(pathCorners);
            }
            else
            {
                float distance2 = (StealList[randNumb].transform.position - transform.position).magnitude;
                if (distance2 <= 1.5f)
                {
                    robber.SetBool("Arrive", true);
                    //robberGame.SetBool("Robbed", true);

                    StealTimer -= Time.deltaTime;
                    if (StealTimer <= 0.1f)
                    {
                        randStealNumb = Random.Range(0, 2);
                        if (randStealNumb == 1)//steal
                        {
                            robber.SetBool("Steal", true);
                            robber.tag = "Robber";
                            stealed    = true;
                        }
                        else
                        {
                            stealed = false;
                        }
                        robber.SetBool("Arrive", false);
                        StealList.Clear();
                        StealList = null;

                        StealTimer = 5.0f;
                    }
                }
            }
        }
        else
        {
            if (stealed == true)
            {
                move.max_mov_velocity = 3;
            }
            if (goingHome == false)
            {
                goingHome = true;

                distance = (home.transform.position - transform.position).magnitude;
                NavMeshPath nerdPath = new NavMeshPath();
                m_robber.CalculatePath(home.transform.position, nerdPath);
                Vector3[] pathCorners = new Vector3[nerdPath.corners.Length];
                nerdPath.corners.CopyTo(pathCorners, 0);
                seek.SetPathCorners(pathCorners);
            }
            else
            {
                float distance2 = (home.transform.position - transform.position).magnitude;
                if (distance2 <= 1.5f)
                {
                    Destroy(this.gameObject);
                }
            }
        }
    }