(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotShell_X : MonoBehaviour
{
public GameObject shellPrefab;
private int count;
private void Update()
{
count += 1;
if(count % 100 == 0)
{
// 右
GameObject shell_R = Instantiate(shellPrefab, transform.position, Quaternion.identity);
Rigidbody shellRb_R = shell_R.GetComponent<Rigidbody>();
shellRb_R.AddForce(transform.right * 200);
Destroy(shell_R, 5f);
// 左
GameObject shell_L = Instantiate(shellPrefab, transform.position, Quaternion.identity);
Rigidbody shellRb_L = shell_L.GetComponent<Rigidbody>();
shellRb_L.AddForce(-transform.right * 200);
Destroy(shell_L, 5f);
}
}
}
(実行結果)