So I’ve been making a simple FPS game for webGL, and in the latest build a few in my team ( 2 out of 5 ) experience this issue that they cant shoot (damage) enemies. They have similar specs pc and use same browser (tried with Chrome, Brave, FireFox).
The guns are copy pasted, the material is only different. It works (for them) with one gun but dosent with another.
On editor and my browsers (and for the others in the team) works fine.
Normally I would google and modify the script but I’ve been stuck with this bug for two months and it’s especially a hassle to have to build > send to be uploaded on web > and have everyone always test, instead of just seeing if it works on the editor/my pc.
I’m open for better workflows
Any ideas on what to do or any clue what to look for would mean a lot!
P.S. I’m more less a beginner developer with basic coding/unity knowledge, so Step by Step explanations would also be greatly appreciated!
will it get fixed if we change platform perhaps?
more on how it works:
in the main menu the player chooses which gun he will use, and a string (name of the gun) is sent to a script (in a level) that turns on the gun object (gun name = string name) and disables other ones**(gun objects in list)**. My guess ether it’s a ray cast issue (i had one a few months ago) or in worst case scenario a Unity thing.
I dont know if might help but theres also a small issue when the player is pointing a “interactable” object (tag) sometimes the sprite (hand) dosent show up. It works for some object and for others dosent (only the object un that group that is the model is different).
On debug.log the messeage stop at “gun has shot 2”.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class shoot_re : MonoBehaviour {
[Header("References")]
[SerializeField] private gun_data gunData;
[SerializeField] private Transform cam;
[SerializeField] private KeyCode reloadKey = KeyCode.R;
//float timeSinceLastShot;
// public float RateOfFire = 0.25f;
private float nextShot;
public ParticleSystem muzzleFlash;
private Animator gunAnim;
public LayerMask layerMask;
private float damageMax;
private float damageRange;
private int damageRegular;
private float damageHead;
public float damageMaxHead;
private float damageRangeHead;
private int damageRegularHead;
// private AudioSource audioSource;
public AudioSource gunAudio;
public AudioClip gunRLoad;
public Text ammoText;
public Text magText;
private void Start() {
// PlayerShoot.shootInput += Shoot;
// PlayerShoot.reloadInput += StartReload;
gunAudio = GetComponent<AudioSource>();
// gunRLoad = gameObject.AddComponent<AudioSource>();
gunAnim = GetComponent<Animator>();
gunData.currentAmmo = gunData.magSize;
gunData.magNumb = 2;
damageMax = gunData.damage + gunData.damage / 2;
}
private void OnDisable() => gunData.reloading = false;
private void StartReload() {
if (!gunData.reloading && this.gameObject.activeSelf)
StartCoroutine(Reload());
}
private IEnumerator Reload() {
gunData.reloading = true;
gunAnim.SetTrigger("Reload");
gunAudio.PlayOneShot(gunRLoad, 0.7f);
yield return new WaitForSeconds(gunData.reloadTime);
gunData.currentAmmo = gunData.magSize;
gunData.magNumb -= 1;
gunData.reloading = false;
}
// private bool CanShoot() => !gunData.reloading && timeSinceLastShot > 1f / (gunData.fireRate / 60f);
// private bool Shet = true;
public void Update() {
ammoText.text = gunData.currentAmmo + "";
magText.text = "" + gunData.magNumb;
damageRange = Random.Range(gunData.damage, damageMax);
damageRegular = Mathf.RoundToInt(damageRange);
if(Input.GetKeyDown(reloadKey) && gunData.magNumb > 0 && gunData.magSize/2 > gunData.currentAmmo) {
StartReload();
}
if (Input.GetButtonDown("Fire1") && !gunData.reloading && Time.time > nextShot){
nextShot = Time.time + gunData.fireRate;
Debug.Log("gun has shot");
//RaycastHit hit;
if (gunData.currentAmmo > 0) {
// if(CanShoot()) {
//Debug.Log("BRUUUUUUUUH");
gunAnim.SetTrigger("Shoot");
OnGunShot();
Debug.Log("gun has shot 2");
if(Physics.Raycast(cam.position, cam.forward, out RaycastHit hit, gunData.maxDistance, layerMask)) {
// if (health != null)
// {
ShootableBox health = hit.transform.GetComponent<ShootableBox>();
bool head = false;
Debug.Log("ray casted");
if(hit.collider.tag == "Head"){
//ShootableBox health = hit.transform.GetComponentInParent<ShootableBox>();
float damageHead = gunData.damage + gunData.damage / 2;
damageMax = damageHead + gunData.damage;
damageRange = Random.Range(damageHead, damageMax);
damageRegular = Mathf.RoundToInt(damageRange);
damageMax = gunData.damage + gunData.damage / 2;
health.Damage (damageRegular);
head = true;
Debug.Log("shot enemys head");
}
if(hit.transform.tag == "Enemy" & !head){
//ShootableBox health = hit.transform.GetComponent<ShootableBox>();
damageMax = gunData.damage + gunData.damage / 2;
health.Damage (damageRegular);
Debug.Log("shot enemy");
}
Debug.Log("shot enemy fin");
// }
}
gunData.currentAmmo--;
//timeSinceLastShot = 0;
// }
}else if (gunData.magNumb >0){
StartReload();
}
else{
Debug.Log("no more ammo");
}
}
//private void Shoot() {
// timeSinceLastShot += Time.deltaTime;;
// }
}
private void OnGunShot() {
//Effects
gunAudio.time = 0.4f;
gunAudio.Play();
muzzleFlash.Play();
}
}