アイテムの移動&自然消滅


アイテムの移動&自然消滅
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class ItemBase : MonoBehaviour
{
public AudioClip sound;
// ★追加
private void Start()
{
// 一定時間経過後に消す(設定時間は自由)
Invoke("SelfDestroy", 5.0f);
}
// ★追加
private void Update()
{
// ゆっくり下方向に移動させる(移動速度は自由)
transform.Translate(new Vector3(0, 0, -0.01f), Space.World);
}
// ★追加
void SelfDestroy()
{
Destroy(gameObject);
}
public void ItemGet()
{
Destroy(gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}

【2021版】Danmaku(基礎/全55回)
他のコースを見る

アイテムの移動&自然消滅
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class ItemBase : MonoBehaviour
{
public AudioClip sound;
// ★追加
private void Start()
{
// 一定時間経過後に消す(設定時間は自由)
Invoke("SelfDestroy", 5.0f);
}
// ★追加
private void Update()
{
// ゆっくり下方向に移動させる(移動速度は自由)
transform.Translate(new Vector3(0, 0, -0.01f), Space.World);
}
// ★追加
void SelfDestroy()
{
Destroy(gameObject);
}
public void ItemGet()
{
Destroy(gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}

アイテムの移動&自然消滅