using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Des : MonoBehaviour {
private int i = 0;
public int timer = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
i++;
if (i == timer)
{
Destroy(gameObject);
}
}
}
и повесить его на игровой объект, чтобы он через 100 секунд уничтожился.
вот код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gunscript : MonoBehaviour
{
public Transform bullet;
public int BulletForce = 5000;
public int Magaz = 30;
public AudioClip Fire;
public AudioClip Reload;
void Update()
{
if (Input.GetMouseButtonDown(0) & Magaz > 0)
{
Transform BulletInstance = (Transform)Instantiate(bullet, GameObject.Find("Spawnpistols").transform.position, Quaternion.identity);
BulletInstance.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce);
Magaz = Magaz - 1;
GetComponent<AudioSource>().PlayOneShot(Fire);
GetComponent<AudioSource>().PlayOneShot(Reload);
}
if (Input.GetKeyDown(KeyCode.R))
{
Magaz = 30;
}
}
}