Horje
how to spawn a object in unity Code Example
how to spawn a object in unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class spawnObject : MonoBehaviour
{
    //Here, we declare variables.
    public GameObject objToSpawn;
    //public means the var is exposed in the inspector, which is super helpful.
    public float timeLeft, originalTime;

	// Update is called once per frame
    void Update()
    {
        //tick down our timer:
        timeLeft -= Time.deltaTime;
        //timeLeft = timeLeft - Time.deltaTime;
        if(timeLeft<=0)
        {
            SpawnIt();

            //reset the time:
            timeLeft = originalTime;
        }

        //let's also spawn on button press:
        if (Input.GetKey(KeyCode.Return))
        {
            SpawnIt();
        }
    }

    void SpawnIt()
    {
        //spawn our coin:
        Instantiate(objToSpawn, transform.position, Quaternion.identity);
    }
}




Csharp

Related
C# list to string one line Code Example C# list to string one line Code Example
c # c^b Code Example c # c^b Code Example
c# loop array back Code Example c# loop array back Code Example
Check if two linked lists merge. If so, where? Code Example Check if two linked lists merge. If so, where? Code Example
c# loop array backwards Code Example c# loop array backwards Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8