Bullet und health script
This commit is contained in:
@@ -1,32 +1,39 @@
|
||||
//Oliver
|
||||
using UnityEngine;
|
||||
|
||||
public class Bullet : MonoBehaviour
|
||||
public class ARBullet : MonoBehaviour
|
||||
{
|
||||
public float speed;
|
||||
public int damage;
|
||||
public int damage = 20;
|
||||
private Vector3 position = Vector3.forward;
|
||||
private Rigidbody rb;
|
||||
void Start()
|
||||
{
|
||||
GetComponent<Rigidbody>();
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.Translate(position.normalized * speed * Time.deltaTime);
|
||||
|
||||
}
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Enemy")
|
||||
{
|
||||
Destroy(collision.gameObject);
|
||||
EnemyHealth enemy = collision.gameObject.GetComponent<EnemyHealth>();
|
||||
|
||||
if (enemy != null)
|
||||
{
|
||||
enemy.TakeDamage(damage);
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else if(collision.gameObject.tag == "Wall")
|
||||
{
|
||||
Destroy(this);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyHealth : MonoBehaviour
|
||||
{
|
||||
public int maxHP = 100;
|
||||
private int curHP;
|
||||
|
||||
void Start()
|
||||
{
|
||||
curHP = maxHP;
|
||||
}
|
||||
public void TakeDamage(int damageAmount)
|
||||
{
|
||||
curHP -= damageAmount;
|
||||
|
||||
if (curHP <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
void Die()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2665e725aa6c7642bb84ea1a671970a
|
||||
Reference in New Issue
Block a user