using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gun : MonoBehaviour
{
public Transform firepoint;
public GameObject bulletPrefab;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public int health = 100;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
/* void OnTriggerEnter(Collider hit)
{
if (hit.gameObject.tag == “KillZone”)
{
Destroy(gameObject);
}
}*/
public void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
void OnTriggerEnter(Collider other)
{
Bullet bullet = other.GetComponent<Bullet>();
if (bullet != null)
{
TakeDamage(Bullet.damage);
}
// Destroy(gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 20f;
public static int damage = 40;
public Rigidbody rb;
void Start()
{
}
void OnTriggerEnter(Collider hitInfo)
{
Enemy enemy = hitInfo.GetComponent<Enemy>();
// BossHealth boss = hitInfo.GetComponent<BossHealth>();
if (enemy != null)
{
enemy.TakeDamage(damage);
}
Destroy(gameObject);
/* if (boss != null)
{
boss.TakeDamage(damage);
}
Destroy(gameObject);
*/
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
Destroy(gameObject, 2);
}
}