In unity3D I am creating and destroying capsule dynamically at run-time. I used space to create capsule and C for destroying.
I want create multiple object and destroy multiple object at time. When I pressed Space multiple times object is creating multiple time it fine.
But the problem is when I pressed C multiple times only one object is destroying. How I can achieve destroying multiple object? One by one.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DynamicCreate : MonoBehaviour
{
public GameObject caps;
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Space))
{
createObject();
}
if (Input.GetKeyDown(KeyCode.C))
{
destroyObject();
}
}
private void createObject()
{
caps = GameObject.CreatePrimitive(PrimitiveType.Capsule);
}
public void destroyObject()
{
Destroy(caps);
}
}