Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Venla · Dec 18, 2017 at 02:37 AM · shaderienumeratorfadeoutfadeinhp

Can't quite figure out how to make this bit of code work. Help please?

I'm still somewhat of a beginner, but I'm trying to figure out how to make this work and I cannot seem to find anything quite like what I'm looking for. The idea of this script is that when the HP bar appears when the player is hit. That works as the hitState is activated. The problem is it never deactivates. I've tried adding a timer via WaitForSeconds and trying to have it switch back off. However, it tells me that on line 44 that the best overloaded math for StartCoroutine has some invalid arguments. The second error is also on line 44 as it says argument #1 cannot covert 'method' group' expression to type 'System.Collections.IEnumerator'

I am aware the code looks a bit weird as it's also finding another component from another script. Pretty much the clampTag only serves to pin the HP bar UI above the player's head at all times. The below is the script in question.

 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class HpBarBehavior : MonoBehaviour
 {
     public Image UiTag;
     public bool hitState = false;
     public float fadeTime;
     public float fadeInstruction;
     private const float BarFadeDuration = 1.0f;//time tofade in/out the bar
     private float _fadeTimer = 0.0f;
     private float timeSinceLastCombat = 10000.0f;
     private const float CombatTimeout = 1.0f;//how long till no incombats starts a fadeout. so that things dont bounce on/off too much
     private float barTimer = 0.0f;
     private float barAlpha = 0.0f;
 
 
     void Start()
     {
         if (hitState == false)
         {
             UiTag.gameObject.SetActive(false);
             GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
             GameObject.Find("tagHolder").GetComponent<ClampTag>();
         }
  
     }
 
     public void inCombat()// call at start of, while still in combat
     {
         timeSinceLastCombat = 0.0f;
     }
 
     // Update is called once per frame
     public void Update()
     {
         if (hitState == true)
         {
             UiTag.gameObject.SetActive(true);
             GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
             GameObject.Find("tagHolder").GetComponent<ClampTag>();
 
             StartCoroutine(timerCount);
         }
     }
     
     
         public void OnCollisionEnter(Collision collision)
     {
         Debug.Log(collision.gameObject.tag);
         if (collision.gameObject.tag == "Hit")
         {
             hitState = true;
         }
     }
 
     IEnumerator timerCount()
     {
         yield return new WaitForSeconds(5);
 
         UiTag.gameObject.SetActive(false);
         GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
         GameObject.Find("tagHolder").GetComponent<ClampTag>();
     }
 }
 
Comment
Add comment · Show 2
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 DreadKyller · Dec 18, 2017 at 02:57 AM 0
Share

Well timerCount is a function, not a variable, you need to call it. If you look at the examples here: https://unity3d.com/learn/tutorials/topics/scripting/coroutines you'll see that it's being called. Not sure if that's exactly your problem but it's worth testing out.

avatar image Venla DreadKyller · Dec 18, 2017 at 03:37 AM 0
Share

I will most definitely try that out. I did try Coroutines before but I didn't properly understand them.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BastianUrbach · Jan 02, 2018 at 11:25 PM

Try

StartCoroutine(timerCount());
instead of
StartCoroutine(timerCount);
Comment
Add comment · 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

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

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

Related Questions

I need help getting a camera to fade up from black after my player teleports to next room position. 2 Answers

[Solved] Fading Two Materials Using Color 0 Answers

Screen Fader Problem 1 Answer

How to add a scene fader to a timer 0 Answers

How to fade in and out a image in a loop?,How do I fade in and out image on a loop? 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