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 matta9001 · Feb 16, 2014 at 09:57 PM · animationjavascriptscriptingbasicsnoob

Very silly and simple javascript question

I want a gun to be able to shoot while on the hip, shoot while aimed, aim in and aim out. I got the parts working where it zooms in, zooms out, and shoots in the hip, but the last part i just can't get. Look at the last if statement and i need to know what i did wrong' #pragma strict var aim = true;

 function Update (){
     if(Input.GetKeyDown(KeyCode.Mouse0)){
         animation.Play("1911shoot");
     }
     if(Input.GetKeyDown(KeyCode.Mouse1)){
         animation.Play("1911aim");
         aim = false;
     }
     if(Input.GetKeyUp(KeyCode.Mouse1)){
         animation.Play("1911unaim");
         aim = false;
     }
     if(aim == true && Input.GetKeyDown(KeyCode.Mouse0)){
         animation.Play("1911aimShoot");
     }
 }
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 POLYGAMe · Feb 16, 2014 at 10:37 PM 0
Share

Where are you setting aim to true? EDIT: Sorry, I see it is declared as true.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by POLYGAMe · Feb 16, 2014 at 10:42 PM

You've got it running two IF statements at a time... the first one and the last one, and the two in the middle. So if you press mouse 1, it will run both of those missile Ifs, as you haven't specified a condition in which to run it. I'm not too familiar with animations but it looks to me like it will start one animation, then instantly start the next,

Try setting up extra bools like "isAnimating" and wait for that to finish etc.

EDIT: I just notice that one of them is GetKeyUp, so ignore the bit about the two middle IF statements. It will still try and run both the first and last ones though, if the aim boolean is true.

Without knowing exactly what you are trying to do, maybe try:

 if(Input.GetKeyDown(KeyCode.Mouse0))
 {
     if(aim)
     {
         animation.Play("1911aimShoot");
     }
     else
     {
         animation.Play("1911Shoot");
     }
 }
     
Comment
Add comment · Show 3 · 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 matta9001 · Feb 17, 2014 at 03:40 AM 0
Share

Thanks so much, ive only written a total of 5 scripts without tutorials that actually works so yeah im a noob but i really appreciate your help

avatar image POLYGAMe · Feb 17, 2014 at 03:46 AM 0
Share

No worries, I was in the same situation a few years ago. I can make games now :D I'm still not a great coder but hey, I manage to get it done. LOL. Good luck!

avatar image POLYGAMe · Feb 18, 2014 at 09:26 AM 0
Share

Oh, please accept the answer if this helped. Feel free to vote up, too ;)

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

19 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

Related Questions

Which code do I use to change animation of Spine? (Noob..) 1 Answer

Animation doesn't work 1 Answer

Using animations in prefabs 1 Answer

new Vector 3 help 1 Answer

how to manage fbx files animation (blender) in unity using favascript 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