Hi there
Basically I want it to hurt my player then kill the player. Also I want my players bullet to damage the enemy overtime then die.
any help would be greatly appreciated many thanks
peace, love, positivity
Player Shoot Script
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Runtime;
using UnityEngine;
public class PlayerShooting : MonoBehaviour
{
public GameObject BulletPrefab;
public Transform BulletSpawn;
public float damage = 5f;
public float TimeBetweenShots = 0.3333f;
public float m_timeStamp = 0f;
// Ammo
public int maxAmmo = 10;
private int currentAmmo;
public float reloadTime = 1f;
private bool isReloading = false;
//Gun Damage
//Crosshair
void Start ()
{
// Ammo
currentAmmo = maxAmmo;
//Crosshiar
}
void FixedUpdate ()
{
// Ammo
if (isReloading)
return;
if (currentAmmo <= 0)
{
StartCoroutine(Reload());
return;
}
if ((Time.time >= m_timeStamp) && (Input.GetKey(KeyCode.Mouse0)))
{
Fire();
m_timeStamp = Time.time + TimeBetweenShots;
}
//Crosshair
}
// Ammo
IEnumerator Reload()
{
isReloading = true;
yield return new WaitForSeconds(reloadTime);
currentAmmo = maxAmmo;
isReloading = false;
}
void Fire ()
{
// Ammo
currentAmmo–;
var bullet = (GameObject)Instantiate(BulletPrefab, BulletSpawn.position, BulletSpawn.rotation);
// Add velocity to the bullet
bullet.GetComponent().velocity = bullet.transform.forward * 50 ;
// Destroy thebullet after 2 seconds
Destroy(bullet, 1.0f);
//Enemy Target Instead of “hit” I had to put “bullet”
}
}
Enemy Attack Script
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class EnemyAttack : MonoBehaviour {
//public float damage = 5f;
[SerializeField] private Transform player;
[SerializeField] private Transform Spawn;
private void OnTriggerEnter(Collider other)
{
if (other.tag == “Player”)
{
Destroy(other.gameObject);
}
else if(other.tag == “Bullet”)
{
//Score Count what if i can add the same line for the player???
Destroy(gameObject);
ScoreCount.scoreValue += 10;
}
}
}