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 Treker2 · May 21, 2015 at 09:16 AM · scripting problemgameobjectdeathdeactivate

Can't Activate/Deactivate Object!

I can't seem to activate the Death Message in my game when my player dies. I want the message to display for 5 seconds and then disappear, unfortunately I am not getting any error messages so I don't know what it wrong. Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class FallDeath : MonoBehaviour {
 
     private int scene;
     public GameObject DeathMessage;
 
     void OnTriggerEnter(Collider other) {
         scene = Application.loadedLevel;
         Debug.Log ("Triggered");
 
         if (other.gameObject.name == "FPSController") {
 
             DeathMessage.SetActive(true);
             Debug.Log("Activated");
 
         
             System.Threading.Thread.Sleep(5000);
     
 
             DeathMessage.SetActive(false);
             Debug.Log("Deactivated");
 
             Application.LoadLevel(scene);
 
         }
     }
 }
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
1

Answer by abhi_360 · May 22, 2015 at 10:43 AM

 void OnTriggerEnter(Collider other) 
 {
          scene = Application.loadedLevel;
          Debug.Log ("Triggered");
  
          if (other.gameObject.name == "FPSController") {
  
              StartCoroutine(Wait());
  
          }
  }
 
 //Add Coroutine
 
 IEnumerator Wait()
 {
              DeathMessage.SetActive(true);
              Debug.Log("Activated");
  
          
              yield return new WaitForSeconds(5);
      
  
              DeathMessage.SetActive(false);
              Debug.Log("Deactivated");
  
              Application.LoadLevel(scene);
 }

should work try it

System threads take parameters in ms so 5000ms = 5s

Comment
Add comment · Show 3 · 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 Treker2 · May 22, 2015 at 01:59 PM 0
Share

It did not work, no death message and yet the level still reloads

avatar image abhi_360 · May 25, 2015 at 04:49 AM 0
Share

ok the code tested and robust so if its not working check if anything else (else meaning script) has a handle to your deathmessage gameobject.

It may be some other script is resetting it to stay disabled

avatar image barbe63 · May 25, 2015 at 04:59 AM 0
Share

Check :

-if the gameobject is assigned in the inspector

-if its renderer is enabled

-if its color alpha is not 0

The code above should work.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Cannot deactivate / activate gameobject, even in editor! 6 Answers

How to access the properties of any created Game Object from another script Unity C # 2D 1 Answer

Deactivate an object - and all scripts in that object deactivated? 1 Answer

Camera switch between child back to main camera issue 2 Answers

Duplicate object and shooting problem (SOLVED) 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