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 /
avatar image
0
Question by edufissure · Jan 27, 2019 at 08:30 PM · scripting problemcoroutinedelaydestroy object

DisplayText info and wait for animation ends to destroyobject ( time extra box)

 ///using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 // A grenade
 // - instantiates a explosion Prefab when hitting a surface
 // - then destroys itself
 


 public class TriggeredTimeBox : MonoBehaviour
 {
     //You can set this in a prefab: dont be confused and use two at at time
     //public int idMonolith;
     //public int experienceForthisMonolith;
     //public string clue;
     private bool havebeenVisited;
 
     private Animator _anim;
     public Text displayInfo;
 
     private string sDisplayInfo;
     
     /* Usually Awake() is used to initialize if certain values or script are dependent on each other and would cause errors if one of them 
     is initialized too late (awake runs before the game starts). Awake is also called only once for every script instance.
     Codes in Start() function get executed only if the script is activated while, codes in Awake() function get executed even if the script is not activated. Try it !
     */
     void Awake()
     {
         havebeenVisited = false;
         //customImage.enabled = false;
         sDisplayInfo = "";
         displayInfo.enabled= false;
         _anim = GetComponent<Animator>();
     }
     private IEnumerator OnTriggerEnter(Collider other)
     {
      
      PlayerCharacterManager player= other.GetComponent<PlayerCharacterManager>();
         
         //Check if other object is PlayerCharacter
         //if( havebeenVisited == false) havebeenVisited=true;
         float remainingTime = player.getRemainingTime();
         float maxTime = player.getMaxTime();
         sDisplayInfo = "";
         if( player!= null) {
                 if(!havebeenVisited)
                 {
                     //At least we add 10 seconds of time    
                     float timeToAdd = Mathf.Round (Random.Range(10.0f, maxTime));
                     //Condition: at least add one point of health, if HealthToAdd is zero, then assign at least 1.0f
                     //if (HealthToAdd <= 0) HealthToAdd=1.0f;
                     
                     Debug.Log("Time to add : " + timeToAdd);
                     displayInfo.enabled = true;
                                         
                     havebeenVisited=true;
                     
                     Debug.Log("Time increased : " + timeToAdd);
                     player.addTime(timeToAdd);
                     sDisplayInfo = "Time increased + " + timeToAdd.ToString() + " seconds";
                     displayInfo.text = sDisplayInfo;
                     _anim.SetBool( "PlayOpenAnimation", true);
                     float timeAnim = _anim.GetCurrentAnimatorStateInfo(0).length;
                     //_animator.SetInteger("gameResult",1);
                      yield return new WaitForSeconds(timeAnim);
                     
                     
                     
                                     
                     StartCoroutine(Delay());
                         
                         
                 }
                 
             //displayInfo.text = sDisplayInfo;    
         } //End player
     }
 
     //Not used as character cant enter in monolith....
      private void OnTriggerStay(Collider other)
     {
         
     }
      private void OnTriggerExit(Collider other)
     {
       //  ContactPoint contact = collision.contacts[0];
        // Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
         //Debug.Log("Ya no hay tema bfff");
       //  Vector3 pos = contact.point;
        // Instantiate(explosionPrefab, pos, rot);
       //  Destroy(gameObject);
     //  customImage.enabled= false;
        // displayInfo.enabled = false;
     }
      private IEnumerator Delay()
     {
         Debug.Log("Delay Time Box");
         print(Time.time);
         yield return new WaitForSeconds(1.0f);
         print(Time.time);
         displayInfo.enabled = false;
         if ( havebeenVisited) Destroy(this.gameObject);
 
         //Destroy(this.gameObject,2.0f);
     }
     
 }


Please help dont know why isnt working... After animation stops, stills one or two seconds the message and the treasure get in the game

This is a TimeBox, where you can add some random time to your remaining time. I need to show the info, display text for at least 3.0 seconds, enough time to read it, and then or at same time play animation where the treasure chest is moving and rotating before dissapearing....

I ve been working all the afternoon and i cant get the key... any help would be apreciated....

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Function delay? 1 Answer

[HELP] How to make camera smooth change position while follow object? 1 Answer

Endless runner background looping delayed. 0 Answers

How do I delay an Ad? 2 Answers

Can you run a coroutine more often than Update? 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