Hi. The collider of my hitbox gets recognized in the console but it does not apply damage to the enemy script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
public GameObject fpsCam;
public GameObject enemy;
public float headDamage;
public float chestDamage;
public float legDamage;
public float fireRate = 15f;
public Color standard;
public Color hitColor;
public Animator animation;
public AudioSource shootSound;
private float nextFire = 0f;
// Use this for initialization
void Start()
{
animation = this.GetComponent<Animator>();
//standard = enemy.GetComponent<Color>();
//enemy.GetComponent<Renderer>().material.SetColor("_Color", standard);
}
// Update is called once per frame
void Update()
{
//enemy.GetComponent<Renderer>().material.SetColor("_Color", standard);
if (Input.GetMouseButton(0) && Time.time >= nextFire)
{
//ShootWeapon();
nextFire = Time.time + 1f / fireRate;
ShootWeapon();
shootSound.Play();
}
}
public void ShootWeapon()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, 100f))
{
Debug.Log(hit.transform.tag);
animation.Play("AK47");
Enemy enemy = hit.transform.GetComponent<Enemy>();
if (enemy != null)
{
if (hit.collider.tag == "HeadCollider")
{
enemy.TakeDamage(headDamage);
}
if (hit.collider.tag == "ChestCollider")
{
enemy.TakeDamage(chestDamage);
}
if (hit.collider.tag == "LegCollider")
{
enemy.TakeDamage(legDamage);
}
}
}
Debug.DrawRay(fpsCam.transform.position, fpsCam.transform.forward, Color.red, 100f);
}
}
Could Someone pleas help me? I wont be able to assist you to well becauseI am teaching C# to myself.