Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug My objects won't show in the inspector, can't put my prefabs in.

Discussion in 'Scripting' started by annarebeccaunterholzner, Aug 15, 2023.

  1. annarebeccaunterholzner

    annarebeccaunterholzner

    Joined:
    Feb 9, 2021
    Posts:
    2
    What is my error here.. File name and Class name are the same.. Any help really appreciated.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class SpawnObstacles: MonoBehaviour
    {
    public GameObject obstacle;
    public float maxX;
    public float minX;
    public float maxY;
    public float minY;
    public float timeBetweenSpawn;
    private float spawnTime;
    // Update is called once per frame
    void Update()
    {
    if(Time.time > spawnTime)
    {
    Spawn();
    spwanTime = Time.time + timeBetweenSpawn;
    }
    }
    void Spawn()
    {
    float randomX = Random.Range(minX, maxX);
    float randomY = Random.Range(minY, maxY);
    Instantiate(obstacle, transform.position + new Vector3(randomX, randomY, 0), transform.rotation);
    }
    }
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Please use code tags. Please also post the error message you get in the console.

    You have a typo in a variable name in the Update() method. The error message points you to the line and character number with the (xx:yy) numbers in the message.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Are you ignoring any errors? If so, you can't ignore them. it cannot compile the code fully with errors.

    All public fields will show up in the inspector if you have no errors.
     
  4. annarebeccaunterholzner

    annarebeccaunterholzner

    Joined:
    Feb 9, 2021
    Posts:
    2
    THANK YOU!!!
    The fixed Typo did it!