The field 'playermanager. Dead' is assigned but its Value is never used hatası

  • Konuyu başlatan CaGi
  • Başlangıç Tarihi
  • Mesaj 0
  • Görüntüleme 467

CaGi

Hectopat
Katılım
13 Eylül 2020
Mesajlar
162
Arkadaşlar merhaba ben bir oyun denemesi yapıyorum fakat düşman(enemy) canımı götürmüyor ve sarı bir uyarı alıyorum.
1617104639097.png

[CODE title="EnemyManager.cs"]using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyManager : MonoBehaviour
{
public float health;
public float damage;
bool colliderBusy = false;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
private void OnTriggerEnter2D(Collider2D other )
{
if (other.tag=="player" && !colliderBusy)
{
colliderBusy = true;

other.GetComponent<PlayerManager>().GetDamage(damage);
}


else if(other.tag == "Bullet")
{
GetDamage(other.GetComponent<BulletManager>().bulletDamage);



}





}
private void OnTriggerExit2D(Collider2D other )
{
if(other.tag == "player")
{
colliderBusy=false;


}



}


public void GetDamage(float damage)
{
if ((health - damage) >= 0)
{
health -= damage;
}

else
{
health = 0;
}
AmIDead();



}
void AmIDead()
{
if (health<= 0)
{
Destroy(gameObject);


}


}


}[/CODE]
[CODE title="PlayerManager.cs"]using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManager : MonoBehaviour
{
public float health, bulletSpeed;
bool dead = false;
Transform muzzle;
public Transform bullet;

// Start is called before the first frame update
void Start()
{
muzzle = transform.GetChild(1);

}

// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
ShootBullet();


}

}

public void GetDamage(float damage)
{
if ((health - damage) >= 0)
{
health -= damage;
}

else
{
health = 0;
}
AmIDead();



}
void AmIDead()
{
if (health<= 0)
{

dead = true;
}


}

void ShootBullet()
{
Transform tempBullet;

tempBullet = Instantiate(bullet, muzzle.position, Quaternion.identity);
tempBullet.GetComponent<Rigidbody2D>().AddForce(muzzle.forward * bulletSpeed);
}

}[/CODE]
 
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Yeni konular

Geri
Yukarı