(スクリプト)
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShotRod : MonoBehaviour { public GameObject target; public GameObject rodPrefab; private int count; private float dis; private bool attack = false; void Update() { dis = Vector3.Distance(transform.position, target.transform.position); if(dis < 30f) { attack = true; } else { attack = false; } count += 1; if(count % 60 == 0 && attack) { GameObject rod = Instantiate(rodPrefab, transform.position, Quaternion.Euler(90, transform.root.rotation.y, 0)); Rigidbody rodRb = rod.GetComponent<Rigidbody>(); rodRb.AddForce(transform.forward * 2000); Destroy(rod, 5.0f); } } }