41 lines
874 B
C#
41 lines
874 B
C#
//Oliver
|
|
using UnityEngine;
|
|
|
|
public class ARBullet : MonoBehaviour
|
|
{
|
|
public float speed;
|
|
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")
|
|
{
|
|
EnemyHealth enemy = collision.gameObject.GetComponent<EnemyHealth>();
|
|
|
|
if (enemy != null)
|
|
{
|
|
enemy.TakeDamage(damage);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
}
|
|
else if(collision.gameObject.tag == "Wall")
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
}
|