Esempio n. 1
0
    private void OnSpawnGold(SpawnGoldMessage message)
    {
        //we've recived a spawn gold message

        //var transformToSpawnAt = _spawnPositions[Random.Range(0, _spawnPositions.Count)];
        var transformToSpawnAt = _spawnPositions[1];

        //creating a gold prefab in view at the transformToSpawnAt
        var newGameObject = Instantiate(_goldPrefab, transformToSpawnAt);
        //set goldInstance equal to the GoldInstance attached to the new Goldprefab
        var goldInstance = newGameObject.GetComponent <GoldInstance>();

        goldInstance.EntityId = message.EntityId;
        goldInstance.amount   = message.Amount;
        //adding new instnace of gold to the list of current gold in View
        _goldInstances.Add(goldInstance);
    }
Esempio n. 2
0
    public void SpawnGold(int amount)
    {
        //Calling on enityService to create a new ID
        int entityId = _entityService.GetNewEntityId();

        //Creating a new piece of GoldData and assigning it an amount and ID
        GoldData goldData = new GoldData();

        goldData.Amount   = amount;
        goldData.EntityId = entityId;
        //adding this new gold to the List of gold in current Model
        _gold.Add(goldData);

        //creating a new spawn gold message and assgining the same amount and ID
        var message = new SpawnGoldMessage();

        message.Amount   = amount;              //do we need to pass the amount in the message
        message.EntityId = entityId;
        //sending out messsage
        _messageRouter.RaiseMessage(message);
    }