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 Gkoumas · Jul 10, 2017 at 12:58 PM · uiprefabui imagesetactivetime.timescale

text and image prefab not popping up when set.active

Hi guys. I made a script so when a player hit an object a ui window pops up, the scene freezes for 3.5 seconds and then it resumes. Although I managed to run the co routine successfully when the player hits the trigger no UI elements (neither the image nor the text) are popping up. I ve made a prefab for both of them. Any idea why this is happening?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class GUIwin : MonoBehaviour {
 
     public GameObject textprefab;
     public GameObject imageprefab;
 
     IEnumerator OnTriggerEnter(Collider other)
     {
         if (other.CompareTag ("Player")) {
 
             textprefab.SetActive(true);
 
             Time.timeScale = 0.0f;
 
             yield return new WaitForSecondsRealtime(3.5f);
 
             textprefab.SetActive(false);
 
             Time.timeScale = 1.0f;
         }
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by HarshadK · Jul 10, 2017 at 01:15 PM

You need to use instances of these prefabs in the scene. You can create these instances in the editor itself or at runtime. Then assign these instances to their respective variables for text and image.

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 Gkoumas · Jul 10, 2017 at 01:45 PM 0
Share

Not sure what you mean. I made a UI text and image. Then I made empty game objects and I assigned my ui text and ui image to these empty objects. I dragged and dropped them to "Project". What else I need to do?

avatar image HarshadK Gkoumas · Jul 10, 2017 at 01:53 PM 1
Share

After dragging and dropping if your text and image gameobjects are still present in the scene then you need to assign those gameobjects from your scene to your variables and not the prefab from the project tab. If you assign the prefabs from project tab then you need to first instantiate those prefabs in the scene using Instantiate and then set these instantiated gameobject so active.

avatar image Gkoumas HarshadK · Jul 10, 2017 at 02:54 PM 0
Share

No, the text and image gameobjects are not present in the scene. They disappear when I make them child of the gameobject. But even if I assign those gameobjects to my variables nothing seems to change.

Show more comments
avatar image
0

Answer by TheReEvolutions · Jul 10, 2017 at 02:15 PM

Try setting time to 0.001f instead of 0.0f

Comment
Add comment · Show 2 · 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 Gkoumas · Jul 10, 2017 at 02:52 PM 0
Share

I tried it. No real difference.

avatar image TheReEvolutions Gkoumas · Jul 10, 2017 at 02:54 PM 0
Share

are the objects currently in the scene?

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

118 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

Related Questions

How to change Image on button click in a prefab that is instantiated 1 Answer

UI components all disappear on Play mode, then stay invisible 2 Answers

SetActive true not working on UI object 2 Answers

Disable background UI whenever a pop up displays 2 Answers

Fitting a parent UI element to a Child Text's Content 2 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