- Home /
Gun Not working on Web Player
Can any one help me, it seems my gun works great when I'm testing it, but as soon as I build and run it to the web player the gun no longer Fires could someone tell me why this is happening? If you need code or anything let me know I will post it in comments.
Answer by Matt 5 · Jan 17, 2012 at 10:04 PM
private void Update() { if (m_CurrentWeapon != null) { RaycastHit hit; if (Physics.Raycast(Camera.mainCamera.ScreenPointToRay(new Vector3(Camera.mainCamera.pixelWidth / 2f, Camera.mainCamera.pixelHeight / 2f, 0f)), out hit)) { m_CurrentWeapon.Value.transform.rotation = Quaternion.Lerp(m_CurrentWeapon.Value.transform.rotation, Quaternion.LookRotation(hit.point - m_CurrentWeapon.Value.transform.position), Time.deltaTime * 10f); } if (Input.GetButton("Fire1")) { audio.PlayOneShot(LaserBlasts); Weapon weapon = m_CurrentWeapon.Value;
if (weapon.Fire())
{
m_Ammo[weapon.ammoType] = weapon.Reload(m_Ammo[weapon.ammoType]);
}
}
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
m_CurrentWeapon.Value.renderer.enabled = false;
if (m_CurrentWeapon != m_Weapons.Last)
{
m_CurrentWeapon = m_CurrentWeapon.Next;
}
else
{
m_CurrentWeapon = m_Weapons.First;
}
m_CurrentWeapon.Value.renderer.enabled = true;
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
m_CurrentWeapon.Value.renderer.enabled = false;
if (m_CurrentWeapon != m_Weapons.First)
{
m_CurrentWeapon = m_CurrentWeapon.Previous;
}
else
{
m_CurrentWeapon = m_Weapons.Last;
}
m_CurrentWeapon.Value.renderer.enabled = true;
}
}
if (m_PickUp != null && Input.GetButtonDown("Action"))
{
Weapon weapon = m_PickUp.TakeWeapon();
m_PickUp = null;
weapon.transform.parent = m_WeaponHolder;
weapon.transform.position = m_GunPosition.transform.position;
weapon.transform.rotation = m_GunPosition.transform.rotation;
if (!m_Ammo.ContainsKey(weapon.ammoType))
{
m_Ammo[weapon.ammoType] = 0;
}
if (!NeedsAmmo(m_CurrentWeapon.Value.ammoType, m_CurrentWeapon.Value))
{
Ammo ammo = new Ammo(m_CurrentWeapon.Value.ammoType, m_Ammo[m_CurrentWeapon.Value.ammoType]);
m_Ammo.Remove(m_CurrentWeapon.Value.ammoType);
while (ammo.quantity > 0)
{
AmmoPickup.NewPickup(ref ammo, m_CurrentWeapon.Value.m_MagazineSize, m_GunPosition.transform.position, m_GunPosition.transform.rotation);
}
}
WeaponPickup.NewPickup(m_CurrentWeapon.Value, m_GunPosition.transform.position, m_GunPosition.transform.rotation);
m_CurrentWeapon.Value = weapon;
}
}
private void OnWeaponEnter(WeaponPickup pickup)
{
if (ContainsWeapon(pickup.weaponsType))
{
AmmoType type = pickup.weaponsAmmoType;
if (m_Ammo.ContainsKey(type))
{
Ammo taken = pickup.TakeAmmo(Global_AmmoProperties.GetMaxCapacity(type) - m_Ammo[type]);
m_Ammo[type] += taken.quantity;
}
else
{
Ammo taken = pickup.TakeAmmo(Global_AmmoProperties.GetMaxCapacity(type));
m_Ammo[type] = taken.quantity;
}
}
else
{
if (m_Weapons.Count < m_MaxGuns)
{
Weapon weapon = pickup.TakeWeapon();
weapon.transform.parent = m_WeaponHolder;
weapon.transform.position = m_GunPosition.transform.position;
weapon.transform.rotation = m_GunPosition.transform.rotation;
if (m_Weapons.Count > 0)
{
m_CurrentWeapon.Value.renderer.enabled = false;
}
m_CurrentWeapon = m_Weapons.AddLast(weapon);
if (!m_Ammo.ContainsKey(weapon.ammoType))
{
m_Ammo[weapon.ammoType] = 0;
}
}
else
{
m_PickUp = pickup;
}
}
}
private void OnWeaponExit(WeaponPickup pickup)
{
if (m_PickUp == pickup)
{
m_PickUp = null;
}
}
private void OnAmmoEnter(AmmoPickup pickup)
{
AmmoType type = pickup.type;
if (NeedsAmmo(type, null))
{
Ammo taken = pickup.TakeAmmo(Global_AmmoProperties.GetMaxCapacity(type) - m_Ammo[type]);
m_Ammo[type] += taken.quantity;
}
}
private bool ContainsWeapon(WeaponType type)
{
foreach (Weapon weapon in m_Weapons)
{
if (weapon.type == type)
{
return true;
}
}
return false;
}
private bool NeedsAmmo(AmmoType type, Weapon ignore)
{
foreach (Weapon weapon in m_Weapons)
{
if (weapon != ignore && weapon.ammoType == type)
{
return true;
}
}
return false;
}
public bool HasPickup()
{
return m_PickUp != null;
}
public bool AllowUse()
{
return !HasPickup();
}
public bool IsTriggered()
{
return Input.GetButtonDown("Action");
}
}
I had to add it as an answer there weren't enough char in the comments
Thanks for trying, I ended up fixing it, my carelessness resulted in me deleting something in the project. Sorry if I wasted anyone's time
Your answer
Follow this Question
Related Questions
DmC: Devil May Cry Dual Shot? 0 Answers
Firing Sound 2 Answers
How do I get Single ammo reloading to work? 0 Answers
Bullets going wrong direction 1 Answer