Exemple #1
0
    // Spawn an enemy at a transform.
    public GameObject SpawnEnemy(Transform trans, int health, float speedMultiplier, int faith)
    {
        // Instantiate an enemy.
        GameObject enemy = Instantiate(enemyPrefab, trans.position, trans.rotation);
        // Get the enemy's components.
        EnemyStatus      es = enemy.GetComponent <EnemyStatus>();
        EnemyMovement    em = enemy.GetComponent <EnemyMovement>();
        Health           h  = enemy.GetComponent <Health>();
        TimeControllable tc = enemy.GetComponent <TimeControllable>();

        // Pass variables to the spawned enemy.
        es.village        = village;
        es.Died          += EnemyStatus_Died;
        es.faithOnKill    = faith;
        tc.timeController = GetComponent <TimeControllable>().timeController;
        TimeScale.PassTimeScale(enemy, gameObject);
        // Adjust the enemy strength based on the parameters.
        h.SetMaxHealth(health, Health.Type.Null);
        h.SetHealth(health, Health.Type.Null);
        em.MultiplySpeed(speedMultiplier);
        // Add the enemy to the list.
        enemies.Add(es);
        // Return the enemy!
        return(enemy);
    }
Exemple #2
0
    public void CreateCrop(Vector3 location)
    {
        // Instantiate the crop.
        GameObject cropInstance = Instantiate(prefabCrop, location, Quaternion.identity);
        // Pass the time controller reference to the crop.
        TimeControllable tc = cropInstance.GetComponent <TimeControllable>();

        tc.timeController = GetComponent <TimeControllable>().timeController;
        TimeScale.PassTimeScale(cropInstance, gameObject);
        // Pass the food controller reference to the crop.
        PlantStatus ps = cropInstance.GetComponent <PlantStatus>();

        ps.foodController = this;
        // Play crop planting sound.
        audioSource.PlayOneShot(soundPlant);
    }
    private void Start()
    {
        List <Transform> housePositions = kp.GetKeyPoints();

#if PRINT_HOUSE_COUNT
        Debug.Log("Number of houses: " + housePositions.Count);
#endif

        // All of the villagers are spawned here.
        // Loop for each transform.
        foreach (Transform trans in housePositions)
        {
            // Instantiate a new villager.
            GameObject newVillager = Instantiate(villagerPrefab, trans.position, Quaternion.identity);
            // Get the villager's relevant components for assignment operations.
            VillagerMovement vm = newVillager.GetComponent <VillagerMovement>();
            VillagerStatus   vs = newVillager.GetComponent <VillagerStatus>();
            TimeControllable tc = newVillager.GetComponent <TimeControllable>();
            // Assign the house to the villager.
            vm.houseTransform = trans;
            // Pass the shrine to the villager.
            vm.shrine = shrine;
            // Pass the food controller reference to the villager.
            vs.foodController = foodController;
            // Pass village reference to the villager.
            //vs.village = this;
            // Subscribe to the villager's events.
            vs.Died            += VillagerStatus_Died;
            vs.AttackedByEnemy += VillagerStatus_AttackedByEnemy;
            // Pass the time controller to the villager.
            tc.timeController = GetComponent <TimeControllable>().timeController;
            TimeScale.PassTimeScale(newVillager, ts);
            // Add the villager to the list of existing villagers.
            villagers.Add(vs);
        }
    }