Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        susceptible = p;

        peopleArray = new personlogic[p];
        int  houses   = Buildings.residental.Count;
        int  jobs     = Buildings.workplaces.Count;
        bool infected = false;

        Debug.Log(houses);
        for (int i = 0; i < p; i++)
        {
            int   brah = Random.Range(0, houses - 1);
            float x    = Buildings.residental[brah].getX();
            float z    = Buildings.residental[brah].getZ();

            brah = Random.Range(0, jobs - 1);
            float x2 = Buildings.workplaces[brah].getX();
            float z2 = Buildings.workplaces[brah].getZ();

            if (i == 21)
            {
                infected = true;
            }



            personlogic person = Instantiate(personTemplate, new Vector3(x, 0.5f, z), Quaternion.identity);

            person.home     = new Vector2(x, z);
            person.work     = new Vector2(x2, z2);
            person.atHome   = true;
            person.working  = false;
            person.shopping = false;

            person.needStore = Random.Range(0, 10);
            person.needWork  = Random.Range(0, 10);

            if (person.needWork == person.needStore)
            {
                person.needWork += Random.Range(0, 5);
            }

            person.workTime  = Random.Range(0, 10);
            person.storeTime = Random.Range(0, 10);
            if (infected)
            {
                person.infect();
                infected = false;
            }

            //person.gameObject.SetActive(false);
        }
    }
Пример #2
0
    // Update is called once per frame

    /*
     * void Update()
     * {
     * //mouse follow
     * if (Input.GetMouseButtonDown(0))
     * {
     *     Ray ray = cam.ScreenPointToRay(Input.mousePosition);
     *
     *     if (Physics.Raycast(ray, out RaycastHit hit))
     *     {
     *         //move agent
     *         agent.SetDestination(hit.point);
     *     }
     * }
     * }
     */



    void FixedUpdate()
    {
        //Debug.Log(Time.deltaTime);
        //Debug.Log(time);
        //if (Time.deltaTime>time){
        time++;
        //Debug.Log(time);
        //Debug.Log(Time.deltaTime);
        if (!working)
        {
            needWork--;
        }
        if (!shopping)
        {
            needStore--;
        }

        if (needWork == 0 && !shopping)
        {
            Debug.Log("need work");
            working = true;
            gameObject.SetActive(true);
            agent.SetDestination(new Vector3(work.x, work.y, 0.5f));
        }

        if (needStore == 0 && !working)
        {
            shopping = true;
            int ultimatebrahmoment = Buildings.stores.Count;
            gameObject.SetActive(true);

            agent.SetDestination(new Vector3(Buildings.stores[ultimatebrahmoment].getX(), Buildings.stores[ultimatebrahmoment].getZ(), 0.5f));
            store = new Vector2(Buildings.stores[ultimatebrahmoment].getX(), Buildings.stores[ultimatebrahmoment].getZ());
        }

        if (shopping && transform.position.x == store.x && transform.position.z == store.y)
        {
            gameObject.SetActive(false);
            storeTime--;

            if (storeTime == 0)
            {
                storeTime = 50;
                needStore = 150;

                agent.SetDestination(new Vector3(home.x, home.y, 0.5f));
                gameObject.SetActive(true);
            }
        }

        if (working && transform.position.x == work.x && transform.position.z == work.y)
        {
            gameObject.SetActive(false);
            workTime--;

            if (workTime == 0)
            {
                workTime = 50;
                needWork = 150;

                agent.SetDestination(new Vector3(home.x, home.y, 0.5f));
                gameObject.SetActive(true);
            }
        }


        int rand = Random.Range(0, 1000);

        ray = new Ray(transform.position, Vector3.back);
        //Debug.DrawRay(transform.position, Vector3.back, Color.yellow);

        if (Physics.Raycast(ray, out hit, infectionRadius) && hit.transform.CompareTag("Infected"))
        {
            //PROBABILITY STUFF HERE
            if (rand == 69)
            {
                personlogic person = hit.collider.GetComponent <personlogic>();
                person.infect();
                this.tag = "Infected";
            }
        }

        ray.direction = Vector3.forward;
        //Debug.DrawRay(transform.position, Vector3.forward, Color.yellow);

        if (Physics.Raycast(ray, out hit, infectionRadius) && hit.transform.CompareTag("Infected"))
        {
            //PROBABILITY STUFF HERE
            if (rand == 69)
            {
                personlogic person = hit.collider.GetComponent <personlogic>();
                person.infect();
                this.tag = "Infected";
            }
        }

        ray.direction = Vector3.left;
        //Debug.DrawRay(transform.position, Vector3.left, Color.yellow);

        if (Physics.Raycast(ray, out hit, infectionRadius) && hit.transform.CompareTag("Infected"))
        {
            //PROBABILITY STUFF HERE
            if (rand == 69)
            {
                personlogic person = hit.collider.GetComponent <personlogic>();
                person.infect();
                this.tag = "Infected";
            }
        }

        ray.direction = Vector3.right;
        // Debug.DrawRay(transform.position, Vector3.right, Color.yellow);

        if (Physics.Raycast(ray, out hit, infectionRadius) && hit.transform.CompareTag("Infected"))
        {
            //PROBABILITY STUFF HERE
            if (rand == 69)
            {
                personlogic person = hit.collider.GetComponent <personlogic>();
                person.infect();
                this.tag = "Infected";
            }
        }

        //}
    }