Example #1
0
    // Update is called once per frame
    void Update()
    {
        // Sync up the variables
        var localPlayerID = NetworkPlayers.Instance.localPlayer.GetComponent <PlayerSetup>().teamID;

        // Check if the house is under construction
        if (humanBuilt)
        {
            if (!constructionFinished)
            {
                state = States.CONSTRUCTION;

                modelStates[0].SetActive(true);
                modelStates[1].SetActive(false);

                var length = finishedScripts.Length;
                for (var i = 0; i < length; i++)
                {
                    finishedScripts[i].enabled = false;
                }

                GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                GetComponent <Rigidbody>().isKinematic = true;
            }
        }
        else
        {
            if (setup.teamID == 0)
            {
                var length = GameManager.Instance.TeamOneHumans.Count;
                for (var i = 0; i < length; i++)
                {
                    var human = GameManager.Instance.TeamOneHumans[i].GetComponent <HumanAI>();
                    if (!human.hasHome && !human.buildingHouse)
                    {
                        human._house  = this.gameObject;
                        human.hasHome = true;
                        break;
                    }
                }
            }

            if (setup.teamID == 1)
            {
                var length = GameManager.Instance.TeamTwoHumans.Count;
                for (var i = 0; i < length; i++)
                {
                    var human = GameManager.Instance.TeamTwoHumans[i].GetComponent <HumanAI>();
                    if (!human.hasHome && !human.buildingHouse)
                    {
                        human._house  = this.gameObject;
                        human.hasHome = true;
                        break;
                    }
                }
            }

            if (((Sun.Instance.rotation < 90 && Sun.Instance.rotation >= 0) || (Sun.Instance.rotation > 270 && Sun.Instance.rotation <= 360)) && !hasRun)
            {
                if (human != null)
                {
                    human.GetComponent <HumanAI>().humanHips.position = doorPosition.position;
                    human.gameObject.SetActive(true);

                    hasRun = true;
                }
            }
        }

        RunState(); // Run the current house state
    }