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 SirDrunkAlot · May 31, 2015 at 08:03 AM · unity 5scripting problemgameobjectcanvasfadeout

Changing alpha value of a canvas from a different game object

Hi all, I am working on a game built from one scene. this scene includes a canvas(called StartMenu) that is basically "covering" the game scene. when the user puts his finger on the right spot, the canvas disappears(using StartMenu.SetActive (false)) and the game starts. I am trying to make the transition "smooth" by adding a fading effect. I attached the canvas with a script from the following tutorial:

link text

I am having problems activating the method FadeMe() for this specific Canvas. this is how iv'e been trying to access it:

 If(GameStarted)
 {
 GameObject go = GameObject.Find("StartCanvas");
 fadeScript = go.GetComponent<Fade>();
 fadeScript.FadeMe();
 }

what happens is that, when the user puts his finger to start the game, you can see the score started increasing but the StartMenu canvas is not fading.

What am I missing here?

Edited(31.5): Following is the code attached on the Canvas game object

 using UnityEngine;
 using System.Collections;
 
 public class Fade : MonoBehaviour {
 
     public void FadeMe(){
         StartCoroutine (doFade ());
     
     }
     IEnumerator doFade(){
         CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
         while(canvasGroup.alpha > 0){
             canvasGroup.alpha -= Time.deltaTime / 2;
             yield return null;
         }
         canvasGroup.interactable = false;
         yield return null;
     }
 }


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
0

Answer by karma0413 · May 31, 2015 at 12:27 PM

Did you make FadeMe() the function inside the Fade Sript public?

public void FadeMe() {}

Additionally, you did not post any code from within the Fade Script, so we don't know if the problem is how you are accessing the function.. or how you are changing the alpha...

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 SirDrunkAlot · May 31, 2015 at 02:11 PM 0
Share

Hi $$anonymous$$arma, thanks for trying to help. i have edited the post with the Fade class

avatar image karma0413 · May 31, 2015 at 03:15 PM 0
Share

I am not an expert by any means and frankly unfamiliar with co-routines...

However, could you just do me two favors on this script.

*Insert on line 11 inside the doFade "print ("Im trying to fade, but cant");

*insert inside the while-loop (Line13: "print ("$$anonymous$$y alpha is above zero");

Let's see what is not running , and narrow down which line of code is not providing the desired output.

also insert in the DoFade, like on line 12 after you gather the canvasgroup.... Print (CanvasGroup.name);

Sorry, if I don't have a direct answer for you. It looks like it should be working to me also.

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

Please help my head is burning from this problem : i have multiple gameobject , same script 1 Answer

Script on multiple objects not working properly! 1 Answer

Refresh panel with prefab contained value from json that created using array 0 Answers

cannot drag script to player.Guitext error,cannot drag player script to the player in hierarchy 2 Answers

Is there a way to dynamically attach a script to a GameObject during runtime? 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