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 /
This question was closed Jan 19, 2019 at 11:36 PM by LunatiXx.
avatar image
0
Question by LunatiXx · Jan 19, 2019 at 05:52 PM · enemydamageinvulnerability

Temporary invulnerability in a platformer

Hello I'm working on a 2d platformer and I'm trying to give my player invulnerability for 3 seconds after getting hit. but I just cant seem to get it to work. any ideas how to fix this script?

   public class Invulnerability : MonoBehaviour
   {
    private Transform Enemy;
    Renderer rend;
    Color c;
    void start ()
    {
        Enemy = GameObject.FindGameObjectWithTag("Enemy").transform;
        rend = GetComponent<Renderer>();
        c = rend.material.color;
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.tag == ("Enemy") && GameControlScript.health > 0)
            Invoke ("GetInvulnerable", 0.1f);
    }
    IEnumerable GetInvulnerable()
    {
        Physics2D.IgnoreLayerCollision (8, 10, true);
        c.a = 0.5f;
        rend.material.color = c;
        yield return new WaitForSeconds (3f);
        Physics2D.IgnoreLayerCollision (8, 10, false);
        c.a = 1f;
        rend.material.color = c;            
    }
 }
Comment
Add comment · Show 3
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 tormentoarmagedoom · Jan 19, 2019 at 07:27 PM 1
Share

Are you sure is not "IEnumerator" merhod?

avatar image LunatiXx tormentoarmagedoom · Jan 19, 2019 at 09:44 PM 0
Share

I'm gonna try... edit: it now kinda works... but ins$$anonymous$$d of going back to normal it gives me invulnerability forever

avatar image xxmariofer LunatiXx · Jan 19, 2019 at 10:54 PM 0
Share

Why are you using Invoke rather than StartCoroutine? it is not finishing your coroutine? It is the first time i see someone call a coroutine with invoke so not sure if that can give some errors.

1 Reply

  • Sort: 
avatar image
0

Answer by ray2yar · Jan 19, 2019 at 11:02 PM

You need to use "StartCoroutine" instead of invoke. You CAN do this by invoking if you prefer but the structure would be different.

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

Follow this Question

Answers Answers and Comments

101 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

Related Questions

Temporary invulnerability in a platformer 0 Answers

Temporary invulnerability in a platformer 0 Answers

Object Not Recieving Damage 3 Answers

Staged bullet damage? 1 Answer

My Enemy Damage Script not working 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