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 allesisda · Feb 23, 2011 at 08:22 PM · changesystemweaponammo

weapon system script

hi there, i am trying to script a weapon system were i have different weapons and can switch between them. i added ammo too. but every time i want to test it the programm automaticly changes into the pause mode and i can't restart -.-

please help me!

here is my script:

var projectil1:Transform; //Prefab for the projectil of weapon 1 var projectil2:Transform; //Prefab for the projectil of weapon 2 var power1 = 2000; var power2 = 2000; var FireButton = "f"; //Keyboard key used to shoot var ammo_typ1 = 20; //Ammo for weapon 1 var ammo_typ2 = 3; //Ammo for weapon 2 var weapon = 1; //wich weapon is in use var TotalWeaponNumbers = 2; //how many weapons exists in the game

function Update () { print (weapon);

//change weapon: if(Input.GetKeyDown("e")) { if(weapon TotalWeaponNumbers) {weapon = 1;} if(weapon < 1) {weapon = TotalWeaponNumbers;}

//weapons: //weapon 1 if(Input.GetKeyDown(FireButton)) { if(weapon == 1) { if(ammo_typ1>0){ var bullit1 = Instantiate(projectil1, GameObject.Find("spawnpoint").transform.position, Quaternion.identity); bullit1.rigidbody.AddForce(transform.forward*power1); ammo_typ1 -=1; }}}

//weapon 2
if(weapon ==2)
{if(ammo_typ2>0){
var bullit2 = Instantiate(projectil, GameObject.Find("spawnpoint").transform.position, Quaternion.identity);
    bullit2.rigidbody.AddForce(transform.forward*power2);
ammo_typ2 -=1;
}}}

Comment
Add comment · Show 2
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 The-BOOM · Feb 23, 2011 at 09:10 PM 0
Share

please edit this and make all of your code inside the code box, and try spacing out your code, it makes it 100x easier to read, and doesn't make it slower

avatar image FLASHDENMARK · Feb 23, 2011 at 10:33 PM 0
Share

As DastardlyBanana staded Unity wont play the game if you have errors in your scripts.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jason_DB · Feb 23, 2011 at 08:44 PM

The pausing is probably because you're getting an error when you try to play, and Unity is pausing. Check if you have "Error Pause on by clicking the bottom of the Unity window to open the console, then seeing if Error Pause is highlighted.

If there is an error, then editing your question to include the specific error message will make it a lot easier for people to help you fix it.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

GUI does not show my current ammo 0 Answers

How to change part of complex gameobject instantiated from prefab? 1 Answer

Reloader Weapon's Bullet? 0 Answers

Weapon Customizations Script Problem 0 Answers

Creating a weapon script. Need Help / advice. 1 Answer


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