CaGi
Hectopat
- Katılım
- 13 Eylül 2020
- Mesajlar
- 146
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.
[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]
[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]