ゲームでメカニズムを正しく機能させるのに問題があります。基本的には 2 つのゾーンがあります。Collidersight と Colliderfatal です。大砲から発射される砲弾に取り付けられたコライダー球によって定義されます。基本的に、Collidersight ゾーン内にあるオブジェクトは、その特定のゾーン内にある限り表示され、そのゾーンの外にある場合は非表示に戻る必要があります。オブジェクトが Colliderfatal と衝突した場合、シェルが破壊された後でも、そのオブジェクトは永続的に表示されます。gameObjects を個別に初期化しようとしましたが、これは非常に紛らわしく、状況に当てはまらないようです。ゲームオブジェクトは既にシーン内に存在しており、それらをインスタンス化していません。
これがコードです。
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class zone : MonoBehaviour {
public LayerMask m_SightLayers;
public LayerMask s_FatalityLayers;
public Vector3 m_Position;
public float m_Radius;
public float m_Force;
public float s_Radius;
public Vector3 s_Position;
public Invisible1 revealenemy1;
public Invisible1 enemykill1;
public float s_Force;
public InvisibleKill makeDead;
public GameObject EnemyCube1;
//public GameObject enemydead;
bool hasExploded;
public bool inZone;
public bool inKillzone;
//public float removeTime = 5.0f;
bool hasBeenhit;
void Awake(){
GameObject[] objects = GameObject.FindGameObjectsWithTag("Enemy");
}
void start (){
makeDead = (InvisibleKill) EnemyCube1.GetComponent (typeof(InvisibleKill));
revealenemy1 = (Invisible1) EnemyCube1.GetComponent(typeof(Invisible1));
}
void OnCollisionEnter(Collision explode){
if(explode.gameObject.name == "Terrain" || explode.gameObject.name == "EnemyCube" || explode.gameObject.name == "EnemyCube1" ){
hasExploded = true;
}
}
void FixedUpdate ()
{
if (hasExploded == true){
Collider[] collidersight;
Collider[] colliderfatal;
Rigidbody rigidbody;
collidersight = Physics.OverlapSphere (transform.position + m_Position, m_Radius, m_SightLayers);
foreach (Collider collider in collidersight)
{
if(collider.tag == "Enemy"){
Debug.Log("stuff");
}
rigidbody = (Rigidbody) collider.gameObject.GetComponent (typeof (Rigidbody));
if (rigidbody == null)
{
continue;
}
if(rigidbody.gameObject.tag == "Enemy"){
inZone = true;
if(inZone == true){
revealenemy1.Reveal1();
// revealenemy2.Reveal2();
//revealenemy3.Reveal3();
Debug.Log ("hit");
hasBeenhit = true;
if(hasBeenhit == false){
hasBeenhit = false;
// revealenemy1.Hidden();
//// revealenemy2.Hidden2();
// revealenemy3.Hidden3();
}
}else{
}
}
}
//Debug.Log (hasExploded);
colliderfatal = Physics.OverlapSphere (transform.position + s_Position,s_Radius,s_FatalityLayers);
foreach (Collider collider in colliderfatal)
{
inKillzone = true;
rigidbody = (Rigidbody) collider.gameObject.GetComponent (typeof (Rigidbody));
if (rigidbody ==null)
{
continue;
}
rigidbody.AddExplosionForce (s_Force * -1, transform.position + s_Position,s_Radius);
Debug.Log("hasbeenkilled");
}
}
if(hasBeenhit == false){
revealenemy1.Hidden();
//revealenemy2.Hidden2();
//revealenemy3.Hidden3 ();
hasBeenhit = false;
}
if(inKillzone == true){
//EnemyCube1.GetComponentInChildren (typeof(Invisible1));
hasBeenhit = true;
//revealenemy.renderer.enabled = true;
// makeDead.isdead = true;
//(typeof(Invisible1));
}
if(makeDead.isdead == true){
revealenemy1.Reveal1();
}
}
void OnDrawGizmosSelected () {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere (transform.position + m_Position, m_Radius);
//Gizmos.DrawWireSphere (transform.position + s_Position, s_Radius);
}
void OnDrawGizmos()
{
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere (transform.position + s_Position, s_Radius);
}
}