Enemy takes Damage
This commit is contained in:
		@@ -243,9 +243,9 @@ CapsuleCollider:
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  m_Radius: 0.11
 | 
			
		||||
  m_Height: 1
 | 
			
		||||
  m_Height: 0.57
 | 
			
		||||
  m_Direction: 0
 | 
			
		||||
  m_Center: {x: 0, y: 0, z: 0}
 | 
			
		||||
  m_Center: {x: -0.08, y: 0, z: 0}
 | 
			
		||||
--- !u!1 &5432457483690072105
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,10 @@ public class BulletScript : MonoBehaviour
 | 
			
		||||
{
 | 
			
		||||
    public DataBullet dataBullet;
 | 
			
		||||
 | 
			
		||||
    private float damage;
 | 
			
		||||
    private float speed;
 | 
			
		||||
    private int ammo;
 | 
			
		||||
 | 
			
		||||
    public GameObject particalClash;
 | 
			
		||||
    
 | 
			
		||||
    public float lifetime = 3f;
 | 
			
		||||
@@ -20,9 +24,6 @@ public class BulletScript : MonoBehaviour
 | 
			
		||||
    private Ray ray;
 | 
			
		||||
    private RaycastHit hit;
 | 
			
		||||
 | 
			
		||||
    public void damageEnemy(float damageAmount){
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void die(float lifetime){
 | 
			
		||||
        if(time > lifetime){
 | 
			
		||||
@@ -34,17 +35,29 @@ public class BulletScript : MonoBehaviour
 | 
			
		||||
            direction = hit.point - transform.position;//Richtung in die, die Kugel fliegt
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private void OnCollisionEnter(Collision collision){
 | 
			
		||||
        Debug.Log(collision.gameObject.name + " UND HIER IST DER TAG: " + collision.gameObject.tag);
 | 
			
		||||
    public void clashPartcal(Collision collision){
 | 
			
		||||
        ContactPoint contact = collision.GetContact(0);
 | 
			
		||||
        Instantiate(particalClash,transform.position,Quaternion.LookRotation(contact.normal));
 | 
			
		||||
    }
 | 
			
		||||
    private void OnCollisionEnter(Collision collision){
 | 
			
		||||
        Debug.Log(collision.gameObject.name + " UND HIER IST DER TAG: " + collision.gameObject.tag);
 | 
			
		||||
        if(collision.transform.tag == "Enemy"){
 | 
			
		||||
            collision.transform.GetComponent<Enemy>().takeDamage(damage);
 | 
			
		||||
        }
 | 
			
		||||
        clashPartcal(collision);
 | 
			
		||||
        GameObject.Destroy(this.gameObject);
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    // Start is called before the first frame update
 | 
			
		||||
    void Start()
 | 
			
		||||
    {
 | 
			
		||||
        damage = dataBullet.damage;
 | 
			
		||||
        ammo = dataBullet.ammo;
 | 
			
		||||
        speed = dataBullet.speed;
 | 
			
		||||
 | 
			
		||||
        rb = this.GetComponent<Rigidbody>();
 | 
			
		||||
        
 | 
			
		||||
    
 | 
			
		||||
        
 | 
			
		||||
        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0f));
 | 
			
		||||
        CheckForColliders();
 | 
			
		||||
@@ -54,7 +67,7 @@ public class BulletScript : MonoBehaviour
 | 
			
		||||
    // Update is called once per frame
 | 
			
		||||
    void Update()
 | 
			
		||||
    {
 | 
			
		||||
        rb.velocity = direction.normalized * dataBullet.speed;
 | 
			
		||||
        rb.velocity = direction.normalized * speed;
 | 
			
		||||
        die(lifetime);
 | 
			
		||||
        time += Time.deltaTime;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -11,8 +11,4 @@ public class DataBullet : ScriptableObject
 | 
			
		||||
    public float speed = 5f;
 | 
			
		||||
 | 
			
		||||
    public int ammo;
 | 
			
		||||
 | 
			
		||||
    public void setDamage(float damage){
 | 
			
		||||
        this.damage = damage;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,30 +8,25 @@ public class Enemy : MonoBehaviour
 | 
			
		||||
    private bool alive = true;
 | 
			
		||||
    public DataEnemy dataEnemy;
 | 
			
		||||
 | 
			
		||||
    private float health;
 | 
			
		||||
 | 
			
		||||
    private float damage;
 | 
			
		||||
 | 
			
		||||
    public void Start(){
 | 
			
		||||
        health = dataEnemy.health;
 | 
			
		||||
        damage = dataEnemy.damage;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void checkAlive(bool alive){
 | 
			
		||||
        if(!alive){
 | 
			
		||||
            GameObject.Destroy(this.gameObject);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    public void takeDamage(float bulletDamage){
 | 
			
		||||
        dataEnemy.health = dataEnemy.health - bulletDamage;
 | 
			
		||||
        if(dataEnemy.health <= 0){
 | 
			
		||||
        health = health - bulletDamage;
 | 
			
		||||
        if(health <= 0){
 | 
			
		||||
            alive = false;
 | 
			
		||||
            checkAlive(alive);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private void OnCollisionEnter(Collision collision){
 | 
			
		||||
        DataBullet bulletData = collision.gameObject.GetComponent<DataBullet>();
 | 
			
		||||
        takeDamage(bulletData.damage);
 | 
			
		||||
        checkAlive(alive);
 | 
			
		||||
    }
 | 
			
		||||
    void Start()
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Update is called once per frame
 | 
			
		||||
    void Update()
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,5 +12,5 @@ MonoBehaviour:
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 9a476e53f7c21af43b8fb3b00b60c337, type: 3}
 | 
			
		||||
  m_Name: EnemyScriptableObject
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  health: 20
 | 
			
		||||
  health: 30
 | 
			
		||||
  damage: 2
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user