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 StigDesign · Oct 28, 2014 at 02:51 PM · weaponweaponsdouble-tap

Double-tap Number keys

Hello am trying to make a fps game. and i try to set up my weapon system i havnt`s goten the script for changing weapons via scroll whell yett but am currious how i can get (Double-tap) effect eks pressing (1) i have a knife but if i press 1 2 times quickly i get another kinife/weapon so instead of be limited to 0-9 i can have 0-9 *2 of weapons :) ps am Norwegian with Dyselexia and am New to UnityAnswer.etc so.

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 SaraCecilia · Oct 28, 2014 at 02:42 PM 0
Share

Hi, you need to re-structure your post. Include all the scripts you are using and what you have tried doing so far to solve this.

avatar image StigDesign · Oct 28, 2014 at 02:47 PM 0
Share

re-structure? yes her is my weapons switching script i use for number`s per weapon i havn`t tried on the Double tap number yett what i mean is that if i press 0 up to 9 i get different weapons but if i double press one of the number i get another weapon so that ins$$anonymous$$d of 10 weapons i can have 20 weapons for a fps game am working on or atleast trying so far only cg has done good. simple weapon switch script below:

 function Awake()
 {
     // Select the first weapon
     SelectWeapon(0);
 }
 
 function Update ()
 {
     //Check if the fire button was pressed
     if(Input.GetButton("Fire1"))
         Broadcast$$anonymous$$essage("Fire");
     
     if(Input.Get$$anonymous$$eyDown("1"))
     {
         SelectWeapon(0);
     }
     else if(Input.Get$$anonymous$$eyDown("2"))
     {
         SelectWeapon(1);
     }
     else if(Input.Get$$anonymous$$eyDown("3"))
     {
         SelectWeapon(2);
     }
     else if(Input.Get$$anonymous$$eyDown("4"))
     {
         SelectWeapon(3);
     }
     
     
 }
 
 function SelectWeapon(index : int)
 {
     for (var i=0;i<transform.childCount;i++)
     {
         // Activate the selected weapon
         if (i == index)
         {
             transform.GetChild(i).gameObject.SetActiveRecursively(true);
         }
         // Deactivate all other weapons
         else
         {
             transform.GetChild(i).gameObject.SetActiveRecursively(false);
         }
     }
 }


am not good at scripting i got this via folowed a digitaltutor tutorial so. if enny input on how to make a simular script but with the doubel press function aswell that whud be greate.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Oct 28, 2014 at 09:19 PM

I didn't test this but this should give you the idea.

  1. if a weapons key was pressed, store which key it was into lastPressedNumber

  2. if a weapons key was pressed, store the time when it happened to lastPressedTime

  3. (otherwise reset both lastPressedNumber and lastPressedTime)

  4. if a weapons key is pressed and the same key was pressed within doubleTapTime seconds, switch to secondary weapon of that key

    var lastPressedNumber : String; var lastPressedTime : Number; var doubleTapTime : Number = 0.3; function Update () { //Check if the fire button was pressed if(Input.GetButton("Fire1")) BroadcastMessage("Fire");

       var timeSincePress: Number = Time.realtimeSinceStartup - lastPressedTime; 
          if(Input.GetKeyDown("1"))
          {
              if (timeSincePress < doubleTapTime && lastPressedNumber == "1")
              {
                  SelectWeapon(10);
              }
              else
              {
                 SelectWeapon(0);
              }
              lastPressedNumber = "1";
          }
          else if(Input.GetKeyDown("2"))
          {
             if (timeSincePress < doubleTapTime && lastPressedNumber == "2")
              {
                  SelectWeapon(11);
              }
              else
              {
                 SelectWeapon(1);
              }
              lastPressedNumber = "2";
          }
          else if(Input.GetKeyDown("3"))
          {
             if (timeSincePress < doubleTapTime && lastPressedNumber == "3")
              {
                  SelectWeapon(12);
              }
              else
              {
                 SelectWeapon(2);
              }
              lastPressedNumber = "3";
          }
          else if(Input.GetKeyDown("4"))
          {
              if (timeSincePress < doubleTapTime && lastPressedNumber == "4")
              {
                  SelectWeapon(13);
              }
              else
              {
                 SelectWeapon(3);
              }
              lastPressedNumber = "4";
          }
          else
          {
              lastPressedNumber = null;
              lastPressedTime = 0;
          }
          
          if (lastPressedNumber != null)
          {
              // something was pressed
              lastPressedTime = Time.realtimeSinceStartup;
          }
      }
      
    
    
    
    
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 StigDesign · Oct 28, 2014 at 09:31 PM 0
Share

oh nice. Thank you so mutch. al see to test it out. i can reply to morrow if it worked with or Withot enny modification. :D i dont have internett in the Norwegian night so+i start at school early but i might be abel to test it and reply quickly as possible. :)

avatar image StigDesign · Oct 29, 2014 at 08:52 PM 0
Share

i tested it i had modify it some and so now it is set properly but it dont work some how with the double press it stil youst work with 0-9. but it got me to think more correctly thoe in scripting. so i might figure it out and post 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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUI display weapon name you are looking at 1 Answer

Weapon shooting mechanism problem. 1 Answer

Weapon switching 1 Answer

methods of positioning weapons to hand 2 Answers

find the angle to rotate the gun to face mouse point with its barrel 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