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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why dosen't this script allow me to assign the prefab?

Discussion in 'Scripting' started by Venatal, Nov 15, 2015.

  1. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    using UnityEngine;
    using System.Collections;

    public class SpawnController : MonoBehaviour
    {
    public GameObject BlueSquare;

    void start()
    {
    StartCoroutine(SquareSpawn());
    }

    IEnumerator SquareSpawn()
    {
    while (true)
    {
    Instantiate(BlueSquare, transform.position, Quaternion.identity);
    yield return new WaitForSeconds(2);
    }
    }


    }
     
  2. michal_k

    michal_k

    Joined:
    Jul 31, 2014
    Posts:
    33
    what is the error?
     
  3. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    There is no error but when I click save and open unity beside the script shouldn't there be a little tab to allow me to assign a prefab to spawn?
    because It's not showing one and in the tutorial I followed it did for the teacher :S
     
  4. michal_k

    michal_k

    Joined:
    Jul 31, 2014
    Posts:
    33
    Show screenshot please.
     
  5. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Did you attach the script to a real GameObject in your scene?

    You can set the prefab only if the script it is attached as a component to an existing game object.
     
    tedthebug likes this.