Help with spawning prefabs

Hello, I completed the Rolling A Ball tutorial, and I was wondering how can I do to spawn another prefab pickup after picking up one before. The mechanic is similar as in the Snake games, where you “eat” or collect a pick up and then another one appears in a random location.

This is my first post in this awesome comunity, I’ll wait your answers and thank you!

Welcome to the Unity Forum.

Instead of setting the active state of the cubes to false when the ball collide with them you could simply move them to a random position on collision.

This is based on the Roll-a-ball tutorial:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerController : MonoBehaviour
{

  public float speed;
  public Text countText;
  public Text winText;
  public float spawnAreaCenterX;
  public float spawnAreaCenterZ;
  public float spawnRadius = 5;

  private Rigidbody rb;
  private int count;

  void Start()
  {
  rb = GetComponent<Rigidbody>();
  count = 0;
  SetCountText();
  winText.text = "";
  }

  void FixedUpdate()
  {
  float moveHorizontal = Input.GetAxis("Horizontal");
  float moveVertical = Input.GetAxis("Vertical");

  Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

  rb.AddForce(movement * speed);
  }

  void OnTriggerEnter(Collider other)
  {
  if (other.gameObject.CompareTag("Pick Up"))
  {
  float xRandomOffset = Random.Range(-spawnRadius, spawnRadius);
  float zRandomOffset = Random.Range(-spawnRadius, spawnRadius);
  float xSpawnPosition = spawnAreaCenterX + xRandomOffset;
  float zSpawnPosition = spawnAreaCenterZ + zRandomOffset;
  other.transform.position = new Vector3(xSpawnPosition, other.transform.position.y, zSpawnPosition);
  count = count + 1;
  SetCountText();
  }
  }

  void SetCountText()
  {
  countText.text = "Count: " + count.ToString();
  if (count >= 12)
  {
  winText.text = "You Win!";
  }
  }
}

This works by setting the spawnArea Center X and Z coordinate in the inspector followed by a “radius” from the spawnArea Center. A random Offset is calculated for both x and z and applied to the “other” object as a vector3 position.