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 ZiggySawdust · May 07, 2014 at 11:21 PM · inputupdate functionpowerup

Input Problems

So I am using a quick powerup system which requires different inputs i want the 'e' button to activate my powerup and then when i click the mouse button i fire 3 balls in a cone. here is my code can anyone help me?

 var projectile : Rigidbody;
 
 var angledifference:float = 20;
 
 function Update () {
 
 if(Input.GetKeyDown(KeyCode.E))
 
     {
         if (Powerup.currentpowerup == 1)
             {
                 MultiBall();
             }
     }
 }
 
 function MultiBall ()
 
 {
 Debug.Log("Running MultiBall");
 
     if(Input.GetMouseButtonDown(0))
     {
     Debug.Log("Clicking Mouse");
     var ballRot= transform.rotation;
     ballRot.x += angledifference;
     var clone : Rigidbody;
         clone = Instantiate(projectile, transform.position, ballRot);
             
             // Give the cloned object an initial velocity along the current 
             // object's Z axis
         clone.velocity = transform.TransformDirection (Vector3.forward * 200);
         
     var ballRot2 = transform.rotation;
     ballRot2.x -= angledifference;    
     var clone2 : Rigidbody;
         clone2 = Instantiate(projectile, transform.position,ballRot2);
             
             // Give the cloned object an initial velocity along the current 
             // object's Z axis
         clone2.velocity = transform.TransformDirection (Vector3.forward * 200);
     }
 }

for some reason it gets to the Runnign Multiball debug line but no further

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 meat5000 ♦ · May 07, 2014 at 11:29 PM 0
Share

Re-formatted your code. Nice try but it went a little wrong :P

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · May 08, 2014 at 01:05 AM

SO.. .this code is only going to work if you hold mouse and press the e button.

Thats because GetKeyDown only fires once per keystroke and, if the mouse button isn't down when it fires and calls Multiball, nothing is going to happen.

If yo uwant to be able to hold the e button and then fire with the mouse while the e button is down, you want to replace GetkeyDown with GetKey. Get key will continue to return true as long as the key is held down.

Finally, if what yo want is for the e key to toggle you into multi-ball mode then you do want GetkeyDown, but you donut want to call multi ball there. Instead you want to set a flag to check inside of your mouse down code to see if its multi ball or not.

I can't give you any more help then that without knowing exactly which effect you a re trying to accomplish.

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
avatar image
0

Answer by robertbu · May 08, 2014 at 01:15 AM

I'm not sure what you want, but here is a try replace Update() with:

 function Update() 
 {
     if(Input.GetKeyDown(KeyCode.E))
     {
         Powerup.currentpowerup = 1;
     }
 
     if(Powerup.currentpowerup == 1 && Input.GetMouseButtonDown(0))
     {
         MultiBall();
     }
 }

An remove the 'if()' condition on line 22 of the MultiBall script.

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

22 People are following this question.

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

Related Questions

What is the best way to watch for button/key presses? 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Tiled Movement Inputs are Inaccurate 1 Answer

Weird Input System situation 1 Answer

Input and Rigidbody (Update and FixedUpdate) 0 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