(方針)
あるボタンを押している間だけ、
- サウンドが鳴り、
- エフェクトが発生する。
ボタンを離すと、
- サウンドが停止し、
- エフェクトも消える。
(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChargeShot : MonoBehaviour
{
public AudioClip shotSound;
public GameObject chargeEffect;
private AudioSource audioSource;
private void Start()
{
audioSource = GetComponent();
}
void Update()
{
if(Input.GetKey(KeyCode.Space))
{
chargeEffect.SetActive(true);
audioSource.enabled = true;
}
else
{
chargeEffect.SetActive(false);
audioSource.enabled = false;
}
if(Input.GetKeyUp(KeyCode.Space))
{
AudioSource.PlayClipAtPoint(shotSound, transform.position);
}
}
}
(設定・構成)


(再生・確認)
- ボタンを押している間だけ、チャージサウンドが鳴り、チャージエフェクトが発生すれば成功

