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 /
  • Help Room /
avatar image
0
Question by texasheadache · Jun 11, 2020 at 12:32 PM · unity 2d

displaying images in canvas problem

Hi - first question here and beginner so please correct me if necessary.

I am working on my first very simple game where the player walks around the graveyard and reads the gravestones. That's it - pretty simple, right?

I have created a canvas that holds the images to be assigned to each gravestone. Upon clicking the space bar in front of each grave stone the image containing the text will be set to Activated thus appearing onscreen. I have a script where I assign the appropriate "image of text" to it's assigned gravestone.

I spent last night learning how to get the text to fade in and out as opposed to just appearing. I managed to get something that looks pretty nice! The problem I have now is that the text has some problems removing itself upon off-clicking when there is more than one gravestone with text running this script. It does work fine when only one gravestone is fully featured with this fading in of the "image of text". Here's the scripts I'm working with:

  1. First is my "SignTwo" script. This is admittedly gleamed a bit from a youtube tutorial on sign text with some modifications to try to implement the fade feature.

    public class SignTwo : MonoBehaviour { public GameObject talkBox; public bool playerInRange;

       void Update()
         {
             if (Input.GetKeyDown(KeyCode.Space) && playerInRange)
             {
                 if (talkBox.activeInHierarchy)
                 {
                    /* talkBox.SetActive(false); */
                     FindObjectOfType<Fade>().FadeMeOut();
                 }
                 else
                 {
                    talkBox.SetActive(true);
                     FindObjectOfType<Fade>().FadeMeIn();
                 }
             }
         }
     
         private void OnTriggerEnter2D(Collider2D other)
         {
             if (other.CompareTag("Player"))
             {
                 playerInRange = true;
             }
         }
     
         private void OnTriggerExit2D(Collider2D other)
         {
             if (other.CompareTag("Player"))
             {
                 playerInRange = false;
                 FindObjectOfType<Fade>().FadeMeOut();
             }
         }
     
         ///method to be used in "Fade" script
         public void Off()
         { 
             talkBox.SetActive(false); 
         }
     }
    
    
    
  2. Second is the "Fade" script which handles the fade feature:

    public class Fade : MonoBehaviour { public void FadeMeOut() { StartCoroutine(fadeOut()); }

       IEnumerator fadeOut()
         {
             yield return StartCoroutine(DoFade());
             /*yield return new WaitForSeconds(2);*/
             yield return StartCoroutine(Offing());
         }
     
      IEnumerator DoFade()
         {
             CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
             while (canvasGroup.alpha > 0)
             {
                 canvasGroup.alpha -= Time.deltaTime / 2;
                 yield return null;
                 
             }
             canvasGroup.interactable = false; 
         }
     
         IEnumerator Offing()
         {
             yield return null; 
             FindObjectOfType<SignTwo>().Off();
         }
     
         public void FadeMeIn()
         {
             StartCoroutine(DoFadeIn());
         }
     
         IEnumerator DoFadeIn()
         {
             CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
             while (canvasGroup.alpha < 1)
             {
                 canvasGroup.alpha += Time.deltaTime / 2;
                 yield return null;
             }
             canvasGroup.interactable = false;
         }
     }
     
    
    

I'm a little stuck here. I wonder if the problem has to do with the single script being applied to multiple objects which turns on and off multiple different images in a single canvas? I've tried duplicated the canvas, and putting each image in its own canvas but that creates more problems of images in some canvases not appearing at all, as well as not being set to "Active(false)" as the script would dictate.

I hope I've been somewhat clear. Can anybody help me understand where my problem might lie?

Thanks!

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

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

Problem with Sprite Editor 0 Answers

I want to generate obj at random places which can move in random speed in X axis.,How to generate a object at random position with varying speed. 1 Answer

how to Spawn (or) delete a 2D Gameobject on collision with a particular gameobject? 0 Answers

Push back kinematic object 0 Answers

Lists not working in an appropriate way,Lists applying to everything in for loop 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