- Home /
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);
}
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.
Good catch ;) It's hard to read such badly formatted code.
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.
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.
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.
Your answer
Follow this Question
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