- Home /
This boolean is messing up. Help?
The particle is supposed to play when Bleeding = true and stop when it equals false. Anyone see an error? I feel like there may be some kind of loop or something making it collide and messing it up.
var Blood : GameObject; var SystemHealth : GameObject; var OrigHealth : float = 300; //Make sure this variable gets subtracted at the same rate as Health. var Health : float = 300; var RobotHealth : float = 800; var BloodCheck : boolean = false; var LimbCheck : boolean = false; var Prop : GameObject; var PropDestination : GameObject; var Robot1 : GameObject; var Robot2 : GameObject; var Robot3 : GameObject; var Robot4 : GameObject;
function Start () { Blood.GetComponent(ParticleSystem).Stop(); }
function Update () { if(BodyArmature.GetComponent(LimbHealth).Health <= 0 && LimbCheck == false) { LimbBroke = true; LimbCheck = true; BodyMesh.renderer.enabled = false;
SystemHealth.GetComponent(MainPlayerHealth).MaxHealth -= Health;
Bleeding = true;
Prop.transform.parent = PropDestination.transform;
Prop.renderer.enabled = true;
Prop.rigidbody.isKinematic = false;
Prop.rigidbody.mass = 1;
Prop.GetComponent(BoxCollider).enabled = true;
}
if(BodyArmature.GetComponent(LimbHealth).Health >= 100 && LimbCheck == true)
{
LimbBroke = false;
LimbCheck = false;
BodyMesh.renderer.enabled = true;
SystemHealth.GetComponent(MainPlayerHealth).MaxHealth += Health;
Bleeding = false;
Prop.renderer.enabled = false;
Prop.rigidbody.isKinematic = true;
Prop.rigidbody.mass = 0.0001;
Prop.GetComponent(BoxCollider).enabled = false;
}
if(BloodCheck == true) {
//FixedUpdate();
BloodCheck = false;
}
if(BloodCheck == false) {
//FixedUpdate();
BloodCheck = true;
}
if(RobotCheck == true) {
Robot1.renderer.enabled = true;
Robot2.renderer.enabled = true;
Robot3.renderer.enabled = true;
Robot4.renderer.enabled = true;
BodyMesh.renderer.enabled = false;
Bleeding = false;
Health = RobotHealth;
BodyMesh.renderer.enabled = false;
}
if(RobotCheck == false && LimbBroke == false) {
Robot1.renderer.enabled = false;
Robot2.renderer.enabled = false;
Robot3.renderer.enabled = false;
Robot4.renderer.enabled = false;
BodyMesh.renderer.enabled = true;
Health = OrigHealth;
}
if(RobotCheck == false && LimbBroke == true) {
Robot1.renderer.enabled = false;
Robot2.renderer.enabled = false;
Robot3.renderer.enabled = false;
Robot4.renderer.enabled = false;
BodyMesh.renderer.enabled = false;
Bleeding = true;
Health = OrigHealth;
}
if(Bleeding == false) {
Blood.GetComponent(ParticleSystem).Stop();
}
if(Bleeding == true) {
Blood.GetComponent(ParticleSystem).Play();
}
}
function FixedUpdate() {
if(Bleeding == true) {
SystemHealth.GetComponent(MainPlayerHealth).MaxHealth -= BloodLoss; yield WaitForSeconds(5); } }
As @Seth Bergman said, yield is not allowed in periodic functions like Update, LateUpdate and FixedUpdate. But what is really messed is your code formatting! Please try to paste the code again, and format it using the <pre> tag: skip a blank line, place the <pre> tag, paste the code and place a closing </pre> tag - this avoids the boring HT$$anonymous$$L equivalents that are plaguing this site.
For now I just got rid of the whole yield thing. Right now my focus is on making it bleed. I will space it out to make it easier to read for you. Sorry if some of it is not spaced right.
var Blood : GameObject;
var SystemHealth : GameObject;
var OrigHealth : float = 300; //$$anonymous$$ake sure this variable gets subtracted at the same rate as Health.
var Health : float = 300;
var RobotHealth : float = 800;
var BloodCheck : boolean = false;
var LimbCheck : boolean = false;
var Prop : GameObject;
var PropDestination : GameObject;
var Robot1 : GameObject;
var Robot2 : GameObject;
var Robot3 : GameObject;
var Robot4 : GameObject;
function Start () { Blood.GetComponent(ParticleSystem).Stop(); }
function Update () { if(BodyArmature.GetComponent(LimbHealth).Health <= 0 && LimbCheck == false) { LimbBroke = true;
LimbCheck = true;
Body$$anonymous$$esh.renderer.enabled = false;
SystemHealth.GetComponent($$anonymous$$ainPlayerHealth).$$anonymous$$axHealth -= Health;
Bleeding = true;
Prop.transform.parent = PropDestination.transform;
Prop.renderer.enabled = true;
Prop.rigidbody.is$$anonymous$$inematic = false;
Prop.rigidbody.mass = 1;
Prop.GetComponent(BoxCollider).enabled = true;
}
if(BodyArmature.GetComponent(LimbHealth).Health >= 100 && LimbCheck == true)
{
LimbBroke = false;
LimbCheck = false;
Body$$anonymous$$esh.renderer.enabled = true;
SystemHealth.GetComponent($$anonymous$$ainPlayerHealth).$$anonymous$$axHealth += Health;
Bleeding = false;
Prop.renderer.enabled = false;
Prop.rigidbody.is$$anonymous$$inematic = true;
Prop.rigidbody.mass = 0.0001;
Prop.GetComponent(BoxCollider).enabled = false;
}
if(RobotCheck == true) {
Robot1.renderer.enabled = true;
Robot2.renderer.enabled = true;
Robot3.renderer.enabled = true;
Robot4.renderer.enabled = true;
Body$$anonymous$$esh.renderer.enabled = false;
Bleeding = false;
Health = RobotHealth;
Body$$anonymous$$esh.renderer.enabled = false;
}
if(RobotCheck == false && LimbBroke == false) {
Robot1.renderer.enabled = false;
Robot2.renderer.enabled = false;
Robot3.renderer.enabled = false;
Robot4.renderer.enabled = false;
Body$$anonymous$$esh.renderer.enabled = true;
Health = OrigHealth;
}
if(RobotCheck == false && LimbBroke == true) {
Robot1.renderer.enabled = false;
Robot2.renderer.enabled = false;
Robot3.renderer.enabled = false;
Robot4.renderer.enabled = false;
Body$$anonymous$$esh.renderer.enabled = false;
Bleeding = true;
Health = OrigHealth;
}
if(Bleeding == false) {
Blood.GetComponent(ParticleSystem).Stop();
}
if(Bleeding == true) {
Blood.GetComponent(ParticleSystem).Play();
}
}
That's the method I used in all my answers - hope UA doesn't change it in the future! The only problem with this method is the < character: UA thinks it's opening a tag and eats all text until a closing > is found. This can be avoided using its HT$$anonymous$$L equivalent (<) or placing a space after the < character.
okay, first off, you could just say
var Blood : ParticleSystem;
Blood.Play();
I''ve not played with the new particles yet much, so I don't know if calling it every frame is an issue, but you may want to use a check to know when to play:
if(Bleeding == true && !Blood.isPlaying) {
Blood.Play();
}
otherwise this looks ok I'll update my answer too..
Answer by Seth-Bergman · Aug 16, 2012 at 01:17 AM
well for starters, you can't say : yield WaitForSeconds(5); in FixedUpdate(), you would need to create a separate coroutine
var loseHealth = false;
function FixedUpdate() {
if(Bleeding) {
Bleed();
}
function Bleed(){
if(!loseHealth){
loseHealth = true;
SystemHealth.GetComponent(MainPlayerHealth).MaxHealth -= BloodLoss;
yield WaitForSeconds(5);
loseHealth = false;
}
something like this maybe
(FixedUpdate is called EVERY fixed frame, so WaitForSeconds won't work)
EDIT: okay, first off, you could just say
var Blood : ParticleSystem;
Blood.Play();
just for the sake of ease
I''ve not played with the new particles yet much, so I don't know if calling it every frame is an issue, but you may want to use a check to know when to play:
if(Bleeding && !Blood.isPlaying) {
Blood.Play();
}
otherwise this looks ok I think..
also make sure RobotCheck is not true of course, can't see where that's set... in fact, I don't see RobotCheck declared at all, did you mean BloodCheck?
For now, robot check is something I am doing manually. When it is true, a robot arm takes the place of the lost arm. If the arm is not lost, than it will go invisible and the robot arm will take its place. Everything works great except the blood. I will try your method when I get home. How is it supposed to help exactly?
Okay. It still isn't working, but I noticed that the white dots representing that a particle exists, goes away (meaning it's playing) But it's not playing. Also, the blood does work at first. It stops running because bleeding = false. But they won't play back. Any idea?
Your answer

Follow this Question
Related Questions
Why will this particle not play? 0 Answers
How do I enable or disable a ParticleRenderer attached to an object in script? 1 Answer
Particle has 2 materials, overlay eachother 1 Answer
How make particle blitz???? 3 Answers
Two Particle Systems 1 Answer