Ejemplo n.º 1
0
    // TODO: Display prompt saying player can't build
    // FixedUpdate function
    private void FixedUpdate()
    {
        if (requestToBuild)                                                         // Player requested to build
        {
            if (currentBuilding.isBuildable(spawnPoint))                            // Determine if player is able to build
            {
                if (playerResource.GetResourceCount() >= currentBuilding.buildCost) // Determine if player has enough resource
                {
                    canRequest = false;
                    audioManager.PlaySound("Deploy");
                    currentBuilding.Build(spawnPoint, grid);
                    playerResource.DisplayNumber(-currentBuilding.buildCost, Color.red);
                    playerResource.DecrementResource(currentBuilding.buildCost);
                    StartCoroutine(Wait(buildRate));
                }
                else
                {
                    Debug.Log("Not enough resource!");
                }
            }
            else
            {
                Debug.Log("Cannot build right now");
            }

            requestToBuild = false;
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!freeze)
        {
            if (!movingToPlanet)
            {
                //Move
                Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
                transform.position += movement * speed * Time.deltaTime;

                if (movement.x != 0 || movement.y != 0)
                {
                    anim.SetBool("isMoving", true);
                }
                else
                {
                    anim.SetBool("isMoving", false);
                }

                anim.SetFloat("movingDirection", movement.x);

                //Build
                bool action = Input.GetButtonDown("Jump");

                if (canBuild && action)
                {
                    currentBuildable.Build();
                }
            }
            else
            {
                transform.position = Vector3.Lerp(transform.position, destination, 0.1f);
            }
        }
    }