コード例 #1
0
ファイル: Organism.cs プロジェクト: alkoclick/miniLifeSim
    /// <summary>
    /// Create an identical child and feed it enough nutrients to have a starting health over the minimum (config.startingHealth).
    /// The child will then evolve
    /// </summary>
    public void Reproduce()
    {
        GameObject child       = Instantiate(gameObject, transform.position, transform.rotation);
        Eating     childEating = child.GetComponent <Eating> ();

        foreach (Nutrient nut in config.eating.EgestMoreThan(config.startingHealth))
        {
            childEating.Ingest(nut);
        }
    }
コード例 #2
0
    /// <summary>
    /// Spawns the first organism in a random location within the given ranges.
    /// </summary>
    /// <param name="maxX">Max x in world space</param>
    /// <param name="maxY">Max y in world space</param>
    /// <param name="maxZ">Max z in world space</param>
    void SpawnFirstOrganism(int maxX, int maxY, int maxZ)
    {
        // Spawn the first organism
        GameObject adam       = Instantiate(config.orgPrefab, new Vector3(UnityEngine.Random.value * maxX, UnityEngine.Random.value * maxY, UnityEngine.Random.value * maxZ), Quaternion.identity, transform);
        Eating     adamsMouth = adam.GetComponent <Eating> ();

        // And then feed it a bit, so it will not die immediately
        for (int i = 0; i < 3; i++)
        {
            GameObject newNut = Instantiate(config.nutPrefab);
            adamsMouth.Ingest(newNut.GetComponent <Nutrient> ());
        }
        adam.transform.parent = null;
    }