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 Conect11 · Nov 18, 2013 at 04:48 AM · animationif-statements

Not sure why animation plays automatically

Let's get this out of the way now:

"Play automatically" is not checked.

The loop mode is set to "once."

In the script there is a condition check which says

"if you have 10 photos, the animation will play."

And yet, the animation plays right from the beginning.

Scratching my head on this one, because I'm guessing that the answer is so simple that I'll kick myself for not thinking of it. So hey, I'm hoping you'll kick me. Err, help me. Any help is humbly appreciated. God bless.

Animation Script: - Please note: also tried in Update

 function Start (){ 
 if(CameraFlash.picture >= 10);
 gatefall();
 }
 
 
 function gatefall () {
 yield WaitForSeconds(1.0);
 animation.Play();
 }

Photo Script

 var flash : GameObject;
 var    cameraSound : AudioClip;
 static var picture : int = 0;
 static var takepicture : boolean = false;
 
 function Start() {
 flash.SetActive(false);
 }
 
 function Update() {
 if(Input.GetButtonDown("Sword Slash")){
 if(Inventory.inventoryArray[4] >= 1)
 {
 AudioSource.PlayClipAtPoint(cameraSound, transform.position);
 picture++;
 takepicture = true;
 flash.SetActiveRecursively(true);
 StopFlash();
 }
 }
 }
 
 function StopFlash() {
 yield WaitForSeconds(1.0);
 flash.SetActiveRecursively(false);
 }
Comment
Add comment
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

1 Reply

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

Answer by supernat · Nov 18, 2013 at 05:18 AM

Hehe, this one gets me all the time. You have a semicolon at the end of your if statement for the picture > 10 check.

Comment
Add comment · Show 5 · 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 Bunny83 · Nov 18, 2013 at 05:23 AM 0
Share

Good catch ;) It's hard to read such badly formatted code.

avatar image Conect11 · Nov 18, 2013 at 05:49 AM 0
Share

supernat, you're awesome, thank you so much!!!! Bunny: congratulations, you had you're moment, and your precious $$anonymous$$arma score went up. Hope you enjoyed it. Go be useless somewhere else.

avatar image FLASHDENMARK · Nov 18, 2013 at 07:50 AM 0
Share

He is not being useless at all. I am certain that he indirectly advised you to format your code properly.

Ins$$anonymous$$d of this:

 function Update() {
 if(Input.GetButtonDown("Sword Slash")){
 if(Inventory.inventoryArray[4] >= 1)
 {
 AudioSource.PlayClipAtPoint(cameraSound, transform.position);
 picture++;
 takepicture = true;
 flash.SetActiveRecursively(true);
 StopFlash();
 }
 }
 }

Do this:

 function Update() {
     if(Input.GetButtonDown("Sword Slash")){
         if(Inventory.inventoryArray[4] >= 1){
             AudioSource.PlayClipAtPoint(cameraSound, transform.position);
             picture++;
             takepicture = true;
             flash.SetActiveRecursively(true);
  
             StopFlash();
         }
     }
 }

$$anonymous$$uch better readability.

Well, you can format anyway you want, but you have to learn (and most likely, you will) how to format your code properly. It becomes many, many times easier. And when you write bigger projects format is of the essence.

avatar image Conect11 · Nov 18, 2013 at 01:08 PM 1
Share

Thank you, Orange. You took the time to show me what I needed to correct, rather than withholding that knowledge for yourself. You contributed, rather than just making a snarky comment.

avatar image mattlewis83 · Feb 08, 2014 at 04:02 PM 0
Share

fight nice guys.

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

21 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

Related Questions

If/then statement logic 1 Answer

if statements for animations js 0 Answers

Can I make animations snap to a frame? 1 Answer

WaitForSeconds twice in 1 if statement, not working 2 Answers

Solution for "next" with single button 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