Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy wont take Damage. How could i fix this?,Enemy wont take damage with raycast

$
0
0
The code i currently have is using UnityEngine; public class Target : MonoBehaviour { public float EHealth = 50f; public void TakeDamage(float amount) { EHealth -= amount; if (EHealth <= 0f) { Destroy(gameObject); } } } for the enemy and using UnityEngine; public class Shooting : MonoBehaviour { public float Damage = 10f; public float Range = 100f; public Camera fpsCam; void Update() { if (Input.GetButtonDown("Fire1")) { Shoot(); } } void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, Range)) { Debug.Log(hit.transform.name); Target target = GetComponent(); if (target != null) { target.TakeDamage(Damage); } } } } for my gun

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>