Jak sprawić, by wróg zabił przez Bullet Unity2d
//Put this code on your enemy
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyScript : MonoBehaviour
{
float health = 10;
// use OnCollisionEnter2D if you don't have trigger on your bullet
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.CompareTag("Bullet"))
{
// You just put script where you have saved your bullet's damage
float Damage = other.GetComponent<BulletScript>.Damage;
health -= Damage;
if(health <= 0)
{
Destroy(gameObject);
}
}
}
}
//Put this on your bullet and give your bullet new tag "Bullet"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
public Damage = 5;
}
// after that, enemy will get destroyed after getting touched at least twice
// by your bullet;
Xixika