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 Doneyes · Aug 16, 2012 at 01:09 AM · booleanparticle

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); } }

Comment
Add comment · Show 5
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 aldonaletto · Aug 16, 2012 at 01:26 AM 1
Share

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.

avatar image Seth-Bergman · Aug 16, 2012 at 01:35 AM 0
Share

Thanks! I didn't know you could do that!

it worked!

avatar image Doneyes · Aug 16, 2012 at 01:48 AM 0
Share

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();
 }

}

avatar image aldonaletto · Aug 16, 2012 at 01:54 AM 0
Share

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 (&lt;) or placing a space after the < character.

avatar image Seth-Bergman · Aug 16, 2012 at 01:59 AM 0
Share

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..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 2 · 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 Doneyes · Aug 16, 2012 at 11:19 AM 0
Share

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?

avatar image Doneyes · Aug 17, 2012 at 12:55 AM 0
Share

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

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

10 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

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


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