Search Unity

Script activate after a certain amount of time (CLOSED)

Discussion in 'Scripting' started by LinkingPixels, Jan 21, 2020.

  1. LinkingPixels

    LinkingPixels

    Joined:
    Mar 20, 2019
    Posts:
    10
    Beginner working on a unity school project and got stuck on how to write a code that would make a prefab gameobject duplicate itself one time after a certain amount of time. Tried to use
    examples from Object.Instantiate but can't solve it. Help appreciated.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. public class Gameplay : MonoBehaviour
    5. {
    6.  
    7.     public GameObject coinOriginal;
    8.     public GameObject coinContainer;
    9.  
    10.     void Start()
    11.     {
    12.         CreateCoins(1);
    13.     }
    14.  
    15.     private void CreateCoins(int coinsNum)
    16.     {
    17.         for (int i = 0; i < coinsNum; i++)
    18.         {
    19.             // GameObject CoinClone = Instantiate(coinOriginal);
    20.             GameObject CoinClone = Instantiate(coinOriginal, new Vector3(i * 0.6f, coinOriginal.transform.position.y, i * 0.75f), coinOriginal.transform.rotation);
    21.             void Update()
    22.     {
    23.        
    24.     }
    25. }
    26.     }
    27. }
     
    Last edited: Jan 21, 2020
  2. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331