(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AxisShot : MonoBehaviour
{
public GameObject shellPrefab;
public AudioClip sound;
private int count = 0;
void Update()
{
var input = Input.GetAxisRaw("Vertical");
if(input == 1)
{
count += 1;
if(count == 1)
{
GameObject shell = Instantiate(shellPrefab, transform.position, Quaternion.identity);
Rigidbody shellRb = shell.GetComponent<Rigidbody>();
shellRb.AddForce(transform.forward * 1000);
Destroy(shell, 10f);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
// ジョイスティックから手を離すとリセット
if(input == 0)
{
// リセット
count = 0;
}
}
}
(実行結果)