Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (CrossPlatformInputManager.GetAxisRaw("Tool") > 0)
        {
            var trees = GameObject.FindGameObjectsWithTag("Tree");

            foreach (GameObject tree in trees)
            {
                if (Vector3.Distance(transform.position, tree.transform.position) < 3)
                {
                    audioSource.Play();
                    Destroy(tree);
                    LevelProgression.AddWood(10);
                    LevelProgression.AddSeeds(5);
                }
            }

            var rocks = GameObject.FindGameObjectsWithTag("Rock");

            foreach (GameObject rock in rocks)
            {
                if (Vector3.Distance(transform.position, rock.transform.position) < 30)
                {
                    audioSource.Play();
                    Destroy(rock);
                    LevelProgression.AddStone(10);
                }
            }
        }
    }
Beispiel #2
0
    void SpawnObject()
    {
        Building building = buildings[index];

        if (LevelProgression.getLevel() >= building.lvlReq &&
            LevelProgression.getWood() >= building.woodCost &&
            LevelProgression.getStone() >= building.stoneCost &&
            LevelProgression.getSeeds() >= building.seedCost) // Check if buildable
        {
            // Update game values
            LevelProgression.AddCivPoints(building.civVal);
            LevelProgression.AddPollPoints(building.polVal);
            LevelProgression.AddSeeds(-1 * building.seedCost);
            LevelProgression.AddWood(-1 * building.woodCost);
            LevelProgression.AddStone(-1 * building.stoneCost);

            // Calc location to spawn
            GameObject prefab          = building.obj;
            Vector3    playerPos       = player.transform.position;
            Vector3    playerDirection = player.transform.forward;
            Vector3    spawnPos        = playerPos + playerDirection * spawnDistance;
            spawnPos.Set(spawnPos.x, spawnPos.y, spawnPos.z);

            // Spawn new object
            Instantiate(prefab, spawnPos, prefab.transform.rotation);
        }
    }