- Home /
Question by
fernandovt · Oct 29, 2013 at 11:05 PM ·
pickupaddingparallel
Parallel event in scripts?? One affects the other??
The Matches Script Help:
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613120908im_/https://answers.unity.com/themes/thub/images/avi.jpg)