(2024年4月17日)
<ボスミサイルの向きの調整>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyShotShell : MonoBehaviour
{
public float shotSpeed;
public GameObject enemyShellPrefab;
public AudioClip shotSound;
private int count;
public float stopTimer;
// ★追加(4月17日)
public GameObject fort;
private void Update()
{
count += 1;
stopTimer -= Time.deltaTime;
if (stopTimer < 0)
{
stopTimer = 0;
}
if (count % 100 == 0 && stopTimer <= 0)
{
// ★修正(4月17日)
// 親ではなく、fortの向きに合致させる(ポイント)
GameObject enemyShell = Instantiate(enemyShellPrefab, transform.position, fort.transform.rotation);
Rigidbody enemyShellRb = enemyShell.GetComponent();
enemyShellRb.AddForce(transform.forward * shotSpeed);
AudioSource.PlayClipAtPoint(shotSound, transform.position);
Destroy(enemyShell, 5.0f);
}
}
public void AddStopTimer(float amount)
{
stopTimer += amount;
}
}
<ミサイルの向きの確認>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyController : MonoBehaviour
{
private int checkCount = 0;
public GameObject[] targets;
private int targetNum = 0;
private float maxDis = 5f;
private Component Chase;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("check"))
{
other.GetComponent().material.color = Color.red;
other.gameObject.tag = "ok";
checkCount += 1;
// ★改良
//targetNum += 1;
targetNum = (targetNum + 1) % targets.Length;
}
}
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * 3);
transform.LookAt(targets[targetNum].transform);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * maxDis, Color.red);
if (Physics.Raycast(ray, out hit, maxDis))
{
print("a");
GameObject target = hit.collider.gameObject;
if(target.name == "Tank")
{
print("b");
this.enabled = false;
this.gameObject.GetComponent<ChaseEnemy>().enabled = true;
}
}
}
}
(2024年2月5日)
<実験結果>
・TankにSpere Colliderを追加
・「Is Trigger」にチェック
・「Radius」を「8」に設定
・問題なく反応した!
・「5」でも「3」でも「2」でも反応
・Spere Colliderを外しても反応した!!!