Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Matt 5 · Jan 17, 2012 at 09:53 PM · gunfiring

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Posly · Jan 17, 2012 at 09:59 PM 0
Share

Code please!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Matt 5 · Jan 18, 2012 at 08:59 PM 0
Share

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

avatar image khellstr · Sep 13, 2013 at 12:37 PM 0
Share

Have samekind of problem, could you tell what fixed it?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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

Can't activate my timer for shooting script? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges