示例#1
0
    public void Start()
    {
        GrabSettings();

        rb       = GetComponent <Rigidbody>();
        simCtrl  = GetComponent <SimInstantiator>();
        worldMap = FindObjectOfType <SimulationMap>();
        InvokeRepeating("CalcNeighbors", neighborCalcFreq, neighborCalcFreq);
        InvokeRepeating("Drift", villageNumber / 100f, driftFreq);

        Vector3 scale = gameObject.transform.localScale;

        for (int i = 0; i < population; i++)
        {
            // Make a new agent.
            GameObject clone     = Instantiate(agentPrefab);
            AgentCtrl  cloneCtrl = clone.GetComponent <AgentCtrl>();
            agents.Add(cloneCtrl);
            cloneCtrl.SetHome(this);

            // Set the agent moving along a random direction.
            Rigidbody cloneRB = clone.GetComponent <Rigidbody>();
            cloneRB.velocity = new Vector3(Random.Range(0f, 100f), 0f, Random.Range(0f, 100f));

            // Put the agent somewhere in the village.
            float rndX = Random.Range(-scale.x / 2f, +scale.x / 2f);
            float rndZ = Random.Range(-scale.z / 2f, +scale.z / 2f);
            rndX += gameObject.transform.position.x;
            rndZ += gameObject.transform.position.z;
            clone.transform.position = new Vector3(rndX, 1f, rndZ);    // 1 so agents aren't spawned inside the ground
        }
    }
 public void Start()
 {
     simCtrl = FindObjectOfType <SimInstantiator>();
     rb      = GetComponent <Rigidbody>();
 }