worldPos is not being recognized

I seem to have an error that the instructor does not have, I have done my best to check for inconsistencies however I cannot find any difference between mine and the instructor, here is the code for spawning defenders at the right spot in the glitch garden lesson.

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

public class DefenderSpawner : MonoBehaviour
{
[SerializeField] GameObject defender;
private void OnMouseDown()
{
SpawnDefender(GetSquareClicked());
}
private Vector2 GetSquareClicked()
{
Vector2 clickPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 worldPos = Camera.main.ScreenToWorldPoint(clickPos);
Vector2 gridPos = SnapToGrid(worldpos);
return gridPos;
}

private Vector2 SnapToGrid(Vector2 rawWorldPos)
{
    float newX = Mathf.RoundToInt(rawWorldPos.x);
    float newY = Mathf.RoundToInt(rawWorldPos.y);
    return new Vector2(newX, newY);
}
private void SpawnDefender(Vector2 roundedPos)
{
    GameObject newDefender = Instantiate(defender, roundedPos, Quaternion.identity) as GameObject;
}

}

Sorry to waste y’alls time, found the capitalization error on my own after posting this…

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

Privacy & Terms