UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"damage weapon on shooting"
public class DamageWeapon : MonoBehaviour { public int damage = 5; public float targetDistance; public float allowedDistance = 20; void Update() { if (Ammo.LoadedAmmo >= 1) { if (Input.GetButtonDown("Fire1")) { RaycastHit Shot; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot)) { targetDistance = Shot.distance; if (targetDistance < allowedDistance) { Shot.transform.SendMessage("DeductPoints", damage); } } } } }