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 fernandovt · Oct 29, 2013 at 11:05 PM · pickupaddingparallel

Parallel event in scripts?? One affects the other??

The Matches Script Help:

alt text

1) My Matches Script adds 1 match when i press "f", the problem is that i need that when i press "e" it adds 10 matches for example (a number that can be changed in the inspector please), And this matches are not being added to the var AmountMatches : int; in the Matches script(weird because i thought that if i had var AmountMatches : int; in the pickup script and in the matches script, both will be affected simultaneously...) 2) The Second problem is my script as it is lets the player press "e" multiple times, playing the audio, and adding an extra match each time "e" is pressed, how could i make that this "e" function affect te audio and matches addition ONCE?

Matches Script:

 var currentMatches = 0;//This is the amount RIGHT NOW of Matches. (should be 0 by default.)
 var AmountMatches : int;
 public var MatchesObj1 : GameObject; 
 public var MatchesObj2 : GameObject;
 
 var shootSound:AudioClip;
 
 
 function Start(){
 
 MatchesObj1.active = false;
 MatchesObj2.active = false;
 
 }
 
 function Update () {
     if (Input.GetKeyDown(KeyCode.F)) ToggleMatches();
 }        
 function ToggleMatches () {
 if(currentMatches < AmountMatches)
 {
 MatchesObj1.active = true;
 MatchesObj2.active = true;
 audio.PlayOneShot(shootSound);
 AmountMatches--;
 
 yield WaitForSeconds(9.9);
 
 MatchesObj1.active = false;
 MatchesObj2.active = false;
 //hasta aca
 
 
 }
 }

PickUpMatches Script:

 var MatchesHide : Matches;      //This will be to Hide The Matches Script, in this way I can't 
                                    //light matches until I press "e" over this MatchesBox
 var MatchesObject: GameObject;       //The MatchesBox That will be destroyed after pressing "e"
 var PickupSound: AudioClip;         //Audio for Pickup
 
 var AmountMatches : int;
 
 public var MatchesObj1 : GameObject;        //I will disable this 2 objects, they are combined
 public var MatchesObj2 : GameObject;         // the match lighted in front of the camera
 
 private var inTrigger = false;
 private var hasMatches = false;
 
 function Start ()  
 {
 MatchesObj1.active = false;
 MatchesObj2.active = false;
 
 MatchesHide = GameObject.Find("Player").GetComponent(Matches);  //Finds Matches Script in the Player; Working
 MatchesHide.enabled = false;      //Disables The FlashLight Light Attached to the Player; Working
 
 
 
 }
 
 function OnTriggerEnter(other: Collider){
   if (other.CompareTag("Player")) inTrigger = true;
 }
 
 function OnTriggerExit(other: Collider){
   if (other.CompareTag("Player")) inTrigger = false;
 }
 
 
 function Update ()
 {
      if (inTrigger && Input.GetKeyDown("e") && !hasMatches)
      {
             MatchesHide.enabled = true;
             AmountMatches++;
 
     
             //
 for(var r : Renderer in GetComponentsInChildren(Renderer))    //I disable the entire renderer of the MatchesBox
 {
      r.enabled = false;
 }
 NewFunction(PickupSound);
 }
 }
 
 function NewFunction (playAudio : AudioClip)
 {
     audio.PlayOneShot(playAudio);
     yield WaitForSeconds(0.2); //Wait the audioclip length before destroying
 
     Destroy(MatchesObject);
 
 
 }
 


gamescreen.png (264.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

FlashLight Fixes Please?? 1 Answer

Cant pickup papers with script 2 Answers

error saying first person controller prefab is missing Camera wont let me mouselook in game 1 Answer

adding script to a clone 2 Answers

I need help with my torch/battery pickup script! 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