私が複数の敵を持っているとき、彼らは健康ラウンドアバウトの浮動小数点数を持ってい250.0f
ます。そのため、そのうちの 1 つを撃つと、敵を撃つたびにその数が 50 ずつ減少するはずです。しかし、ここに私の問題があります。最初の敵は約 4/5 ショットで死亡しますが、(最初の敵の後に) 他の敵を撃ち始めると、1 発で死亡します。
Bullet.cs と呼ばれる、プレイヤーの Bullet 用の Bullet スクリプトを次に示します。
public class Bullet : MonoBehaviour {
public GameObject BulletObject;
public GameObject GlobelObjectExplosion;
public GameObject GlobelBulletExplosion;
public float life = 3.0f;
private EnemyAI enemy;
private Transform bulletTransform;
// Use this for initialization
void Start () {
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Enemy")
{
EnemyAI.currEnemyLife -= 50;
Player.score += 50;
//Creates an explosion on collision
GameObject objBullet = Instantiate(GlobelBulletExplosion, transform.position, Quaternion.identity) as GameObject;
Destroy(objBullet, 2.0f);
Debug.Log("ColliderWorking");
if(EnemyAI.currEnemyLife <= 0.0f)
{
Destroy(other.gameObject);
//creates an explosion when enemy is destoryed
GameObject obj = Instantiate(GlobelObjectExplosion, other.gameObject.transform.position, Quaternion.identity) as GameObject;
Destroy(obj, 2.0f);
Player.score += 250;
}
Destroy(gameObject);
}
}
// Update is called once per frame
void Update () {
life -= Time.deltaTime;
transform.Translate(0, 0, Player.bulletSpeed * Time.deltaTime);
if(life <= 0.0)
{
Destroy(gameObject);
}
}
}
EnemyAI.cs と呼ばれる EnemyAI スクリプトは次のとおりです。
public class EnemyAI: MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public GameObject explosion;
public static float maxEnemyLife = 250.0f;
public static float currEnemyLife;
public static float maxEnemyBullets = 60.0f;
public static float currEnemyBullets;
public static float maxEnemyFuel = 1260.0f;
public static float currEnemyFuel;
private Transform myTranform;
public static Transform LocalTransform;
void Awake(){
myTranform = transform;
LocalTransform = myTranform;
}
// Use this for initialization
void Start () {
if(GameObject.FindGameObjectWithTag("Player") != null){
GameObject go = GameObject.FindGameObjectWithTag("Player");
currEnemyFuel = maxEnemyFuel;
currEnemyLife = maxEnemyLife;
currEnemyBullets = maxEnemyBullets;
target = go.transform;
}
}
// Update is called once per frame
void Update () {
if (currEnemyFuel > maxEnemyFuel)
{
currEnemyFuel = maxEnemyFuel;
}
//Debug.DrawLine(target.position, myTranform.position, Color.cyan);
if(currEnemyFuel <= 0.0)
{
currEnemyFuel = 0.0f;
//myTranform.rotation = Vector3.zero;
//myTranform.position = Vector3.zero;
moveSpeed = 0;
}
else if (currEnemyFuel > 0.0)
{
//Look at target
if(GameObject.FindGameObjectWithTag("Player") != null){
myTranform.rotation = Quaternion.Slerp(myTranform.rotation, Quaternion.LookRotation(target.position - myTranform.position), rotationSpeed * Time.deltaTime);
//Move towards Target
myTranform.position += myTranform.forward * moveSpeed * Time.deltaTime;
currEnemyFuel -= 0.2f;
}
}
}
}
誰かに問題があるかどうか、または回避策があるかどうかを調べようとしましたが、ここまたはグーグルで解決策を見つけることができません. それで、私が何か間違ったことをしているのか、それともチュートリアルなどがあるのか 誰かが教えてくれますか.