Ask coding questions

← Back to all posts
Unity help
Bunnytoes (158)

My button won't work and it's super annoying the upgrade code is

if (PlayerStats.Money < turretBlueprint.upgradeCost)
        {
            Debug.Log("Not enough Money");
            return;
        }

        PlayerStats.Money -= turretBlueprint.upgradeCost;

        Destroy(turret);

        GameObject _turret = (GameObject)Instantiate(turretBlueprint.upgradedPrefab, GetBuildPosition(), Quaternion.identity);
        turret = _turret;


        GameObject effect = (GameObject)Instantiate(buildMaster.buildEffect, GetBuildPosition(), Quaternion.identity);
        Destroy(effect, 5f);

        isUpgraded = true;


        Debug.Log("Turret Upgraded!");
    
Answered by Coder100 (18242) [earned 5 cycles]
View Answer
Comments
hotnewtop
Bunnytoes (158)

I turned on the graphics raycaster and it works now

Coder100 (18242)

yeah making sure everything is turned on also helps xd @Bunnytoes

Bunnytoes (158)

@Coder100 :) I still have the issue with the wave spawner

Bunnytoes (158)

@Coder100 this:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;


public class WaveSpawner : MonoBehaviour
{

    public Transform enemyPrefab;
    public Transform SpawnPoint;
    
    

    public float TimeBetweenWaves = 7f;
    private float countdown = 3f;

    public Text waveCountdownText;


    private int WaveIndex = 1;

  
   

    
    void Update()
    {
        

            if (countdown <= 0f)
            {
                StartCoroutine(SpawnWave());

                countdown = TimeBetweenWaves;
            }

            countdown -= Time.deltaTime;

        countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);

        waveCountdownText.text = string.Format("{0:00.00}", countdown);

      




    }

    IEnumerator SpawnWave()
    {
        WaveIndex++;
        PlayerStats.Rounds++;

        for (int i = 0; i < WaveIndex; i++)
        {
            SpawnEnemy();
            yield return new WaitForSeconds(0.7f);
        }

    }

    void SpawnEnemy()
    {
        
        Instantiate(enemyPrefab, SpawnPoint.position, SpawnPoint.rotation);

        



    }


}