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 jakeomonk · Jun 22, 2013 at 09:00 PM · triggerdamagefirehealth

How to create/fix fire damage script????

I have this script i have written to make the fire damage my player but it comes up with an error saying i need to swap the "=" (25,9) with a ":" instead but this leads to more problems please help!!!

 var HealthAmount:int = 1 ;
 var InFire:boolean = false;
 var Interval:int = 1;
 private var FPSInputController:GameObject;
 
 function start ()
 {
     FPSInputController = GameObject.FindGameObjectWithTag("First Person Controller");
 }
 
 function Update ()
 {
     if(InFire)
     {
         HealthScript.Health -= HealthAmount;
         yield WaitForSeconds (Interval);
     }
 }
 
 
 function OnTriggerEnter(other:Collider)
 {
     if (other.GameObject == FPSInputController);
     {
         InFire=true
     }
 }
 
 function OnTriggerExit(other:Collider)
 {
     if (other.GameObject == FPSInputController);
     {
         InFire=false
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Graham-Dunnett · Jun 22, 2013 at 09:04 PM

Line 23 in the code above has a semi-colon at the end of the line. It shouldn't have. You should have a semi-colon at the end of 25. (And the same for lines 31 and 33).

Comment
Add comment · Show 4 · 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 jakeomonk · Jun 23, 2013 at 01:41 PM 0
Share

Thanks that fixed my problem but it now has the error:

Script error: Update() can not be a coroutine.

Please Give me a fix and explain why this error occured

Edit: just realised the "WaitForSeconds (Interval)" is causing the problem but what can i use as an alternative to this.

avatar image AlucardJay · Jun 23, 2013 at 01:48 PM 0
Share

Basically, you cannot use yield in Update.

Update is not a Coroutine.

A coroutine is a function that can suspend its execution (yield) until the given given YieldInstruction finishes.

Update cannot do this (again, it's not a Coroutine).

avatar image AlucardJay · Jun 23, 2013 at 01:55 PM 0
Share

You could either change your health to float and use Time.deltaTime :

 HealthScript.Health -= HealthAmount * Time.deltaTime;

or call a function that has the yield, but you'll need to create a boolean so that the yield function is not called every update.

pseudocode :

 private var isYielding : boolean = false;
 
 function Update()
 {
     if ( InFire && !isYielding )
     {
         ImOnFire();
     }
 }
 
 function ImOnFire()
 {
     isYielding = true;
     HealthScript.Health -= HealthAmount;
     yield WaitForSeconds (Interval);
     isYielding = false;
 }
avatar image jakeomonk · Jun 23, 2013 at 02:13 PM 0
Share

Thank you so much this script is now working perfectly fine once again thanks so much

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

17 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 avatar image avatar image

Related Questions

Enemy Health Damage 2 Answers

My health decreases to fast. 1 Answer

Damage script is screwed up...? what to do? 1 Answer

My bullet script doens't work. 1 Answer

My player HP are get decreased from several GameObjects that has is Trigger on 0 Answers


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