public static AnimalScript SpawnAnimal(GameAnimal gameAnmial)
    {
        // Spawn prefab
        GameObject newAnimal = Instantiate(gameAnmial.animal.model,
                                           gameAnmial.GetPosition(), gameAnmial.GetRotation(), Instance.animalParentTransform);

        // Add AnimalScript
        AnimalScript animalScript = newAnimal.AddComponent <AnimalScript>();

        animalScript.SetAnimal(gameAnmial);

        return(animalScript);
    }
Exemple #2
0
    // Update methods
    private void UpdatePregnancy()
    {
        if (!IsPregnant)
        {
            return;
        }

        gameAnimal.currentPregnantTime += Time.deltaTime;

        if (gameAnimal.currentPregnantTime >= PregnantTime)
        {
            gameAnimal.isPregnant = false;

            GameAnimal toSpawn = new GameAnimal(Animal);
            toSpawn.herdId = gameAnimal.herdId;
            toSpawn.SetPosition(transform.position + new Vector3(Random.Range(-3f, 3f), 0, Random.Range(-3f, 3f)) * Grid.SCALE);
            toSpawn.SetRotation(Quaternion.Euler(0, Random.Range(0, 360), 0));
            toSpawn.grownUp = false;
            toSpawn.age     = 0;
            UnitManager.SpawnAnimal(toSpawn);
        }
    }
Exemple #3
0
 public void SetAnimal(GameAnimal gameAnimal)
 {
     this.gameAnimal = gameAnimal;
 }