我想将“销毁”的代码行延迟 2 秒。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyDestroyer : MonoBehaviour
{
private float bounceSpeed = 13f;
private void OnTriggerEnter2D(Collider2D collision){
if (collision.gameObject.CompareTag("Enemy")){
GetComponent<Rigidbody2D>().velocity = Vector2.up * bounceSpeed;
Destroy(collision.gameObject);
}
}
}
应该是这样的。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyDestroyer : MonoBehaviour
{
private float bounceSpeed = 13f;
private void OnTriggerEnter2D(Collider2D collision){
if (collision.gameObject.CompareTag("Enemy")){
GetComponent<Rigidbody2D>().velocity = Vector2.up * bounceSpeed;
Destroy(collision.gameObject, 2f);
}
}
}