Returning an error in pathfinder script

Hi, attached are the screenshots of the 2 scripts from this lesson. I can’t figure out why it won’t accept

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PathFinder : MonoBehaviour
{
    EnemySpawner enemySpawner;
    WaveConfigSO waveConfig;
    List<Transform> waypoints;
    int waypointIndex = 0;

    void Awake()
    {
        enemySpawner = FindObjectOfType<EnemySpawner>();
    }

    void Start()
    {
        waveConfig = enemySpawner.GetCurrentWave();
        waypoints = waveConfig.GetWayPoints();
        transform.position = waypoints[waypointIndex].position;
    }

    void Update()
    {
        FollowPath();
    }

    void FollowPath()
    {
        if(waypointIndex < waypoints.Count)
        {
            Vector3 targetPosition = waypoints[waypointIndex].position;
            float delta = waveConfig.GetMoveSpeed() * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, delta);
            if(transform.position == targetPosition )
            {
                waypointIndex++;
            }
        }
        else
        {
            Destroy(gameObject);
        }
    }
}

AND-------

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    [SerializeField] WaveConfigSO currentWave;

    void Start()
    {
        SpawnEnemies();
    }

    public WaveConfigSO CurrentWave() 
    { 
        return currentWave; 
    }

    void SpawnEnemies()
    {
        Instantiate(currentWave.GetEnemyPrefab(0), 
            currentWave.GetStartingWayPoint().position, Quaternion.identity);
    }
}

What is the problem? You just posted scripts, but didn’t really tell us what the issue is that you are having.

Silly me, in the first script the line under the start function is returning an error, specifically GetCurrentWave is not available

waveConfig = enemySpawner.GetCurrentWave();

Ah, yes. It’s because there is no GetCurrentWave() in the EnemySpawner. In EnemySpawner it’s just called CurrentWave()

Thanks, it was toward the end of the day, I was tired and he moves fast. Can’t believe I didn’t catch that. I appreciate the speed with which you replied. Solved!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms