Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there!

So I’m new into making games, I’ve just done a fev python projects but never in any other software than html. Now I’m interested in creating games, and what better than start making a 2D Android game? So I’m just half copying a tutorial just to get used to this. While writing the code I got this error;

Assets\Scripts\GameManager.cs(43,28): error CS0103: The name ‘spwanPoint’ does not exist in the current context

I’ve been searching for possible solutions but idk if that’s the solution, they talked about something called RigidBody.

Here’s the code, thanks!

C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{

    public GameObject block;
    public float maxX;
    public Transform spawnPoint;
    public float spawnRate;


    bool gameStarted = false;


    // Update is called once per frame
    void Update()
    {
        
         if(Input.GetMouseButtonDown(0) && !gameStarted  )
         {
             StartSpawning();

             gameStarted= true;
         }


    }




    private void StartSpawning()
    {
        InvokeRepeating("SpawnBlock", 0.5f, spawnRate);
    }



    private void SpawnBlock()
    {
        Vector3 spawnPos = spwanPoint.position;

        spawnPos.x = Random.Range(-maxX, maxX);

        Instantiate( block, spawnPos, Quaternion.identity );


    }
}


What I have tried:

I've tried to change uppercases but nothing.
Posted
Updated 12-Aug-23 10:20am
v2

1 solution

Spelling: it matters!
C#
public Transform spawnPoint;
C#
Vector3 spawnPos = spwanPoint.position;
 
Share this answer
 
Comments
Andre Oosthuizen 13-Aug-23 6:55am    
Happens to all of us, as another poster stated - "my brain is now hurting" :) +5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900