у меня есть ящик на нем висит скрипт чтобы я его мог поднять и взять с него патроны после чего он исчезает using UnityEngine; using System.Collections;
public class AmmoItem : MonoBehaviour { public shooting test;
// Update is called once per frame void Update () { GameObject player = GameObject.FindGameObjectWithTag("Player"); if(Input.GetButtonDown("use")&Vector3.Distance(transform.position, player.transform.position)<4) { test.inventoryAmmoCount += 30; Destroy(gameObject); } } } помогите что сюда дописать чтобы ящик спаунился в том же месте через определенное время?
public class AmmoItem : MonoBehaviour { public shooting test; public float delayTime = 30f; public GameObject newAmmoBox;
// Update is called once per frame void Update () { GameObject player = GameObject.FindGameObjectWithTag("Player"); if(Input.GetButtonDown("use") && Vector3.Distance(transform.position, player.transform.position) <4 && renderer.enabled) { test.inventoryAmmoCount += 30; renderer.enabled = false; StartCoroutine(NewAmmoBox()); } } IEnumerator NewAmmoBox() { yield return new WaitForSeconds(delayTime); Instantiate(newAmmoBox, transform.position, transform.rotation); Destroy(gameObject); } }
все сделал ящик спаунится,но один раз
Добавлено (27 Июл 2014, 20:56) --------------------------------------------- я тут посмотрел и получилось так
Код
using UnityEngine; using System.Collections;
public class AmmoItem : MonoBehaviour { public shooting test; public float delayTime = 30f; public GameObject newAmmoBox;
// Update is called once per frame void Update () { GameObject player = GameObject.FindGameObjectWithTag("Player"); if(Input.GetButtonDown("use") && Vector3.Distance(transform.position, player.transform.position) <4 && renderer.enabled) { test.inventoryAmmoCount += 30; renderer.enabled = false; StartCoroutine(NewAmmoBox()); } } IEnumerator NewAmmoBox() { yield return new WaitForSeconds(delayTime); Instantiate(newAmmoBox, transform.position, transform.rotation); renderer.enabled = true; } }
но ящики теперь стоят на месте и не удаляются, но ящики спаунятся один за другим. Можно ли как-то исправить, чтобы так же спунились один за другим, но при этом удалялись?
МОгу предложить другой вариант. Нужно 2 объекта. Один - ящик, который при входе в него игрока добавляет патроны и исчезает; другой - невидимый бокс, соразмерный ящику, который при входе в него игрока включает таймер и респаунит новый. Блог.