mardi 5 janvier 2021

How do I have random spawns occur every so many seconds?

This is my code, I am very new and don't know what I need to change. I am trying to spawn in knives every so often so my players can pick them up and be able to stab each other for 3 seconds after picking one up. I am able to get the knife to spawn in, but I can get the knife to spawn multiple times, and I definitely can't control how often the knives spawn in. If anyone could look at my code and figuire out what I need to add I would be so thankful.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KnifeSpawns : MonoBehaviour
{
    public GameObject Knifeprefab;
public Vector3 center;
public Vector3 size;


// Start is called before the first frame update
void Start()
{
    SpawnKnife();
}

// Update is called once per frame
void Update()
{
    
}

public void SpawnKnife()
{

    Vector3 pos = center + new Vector3(Random.Range(-size.x/2, size.x/2),Random.Range(-size.z / 2, 
size.z / 2),Random.Range(-size.y/1,size.y/1));

    Instantiate(Knifeprefab, pos, Quaternion.identity);

}

void OnDrawGizmosSelected()
{
    Gizmos.color = new Color(1, 0, 0, 0.5f);
    Gizmos.DrawCube(center, size);
}

}



Aucun commentaire:

Enregistrer un commentaire