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 /
This question was closed May 14, 2018 at 06:39 PM by polan31 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by polan31 · May 14, 2018 at 03:20 PM · textappear

Why is the Winning text appearing after starting the game?

In my animation, after destroying all objects, appears texts: WinningImage, ExitButton, NextLevelButton appear.

I do not understand why: WinningImage, ExitButton, NextLevelButton;, appear immediately after pressing PLAY, while it should be turned off until the animation is won.

Could someone find a mistake?

  using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class Gamer : MonoBehaviour {
     
     [SerializeField]
     Camera camMain; // drag n drop in the inspector
 
     int index =1;
     public GameObject ImageOver, restartButton , menuButton;
 
     public GameObject WinningImage, ExitButton, NextLevelButton ;
 
     public GameObject Manager;
 
 
 
 
     public void OnCollisionEnter2D (Collision2D col)
     {
         Debug.Log("Player hit object: " + col.transform.name);
         //check if the object you hit is one of the "collisionObjects":
         collisionObject colObj= col.transform.GetComponent<collisionObject>();
         if(!colObj) return;
         CheckDestroyedIndex(colObj);
 
 
     }
     void CheckDestroyedIndex(collisionObject cObj) {
         if(index == cObj.myIndexNumber)
         {
             if (cObj.isHighestNumber)
             {
                 Debug.Log ("Yay you correctly hit the last Square, You WIN!");
                 WinningImage.SetActive (true);
                 restartButton.SetActive (true);
                 gameObject.SetActive (false);
                 Manager.SetActive (false);
 
             }
             Destroy(cObj.gameObject);
             index++;
         }
         // here, we know it didn't match the number. :)
         else
         {
             ImageOver.SetActive (true);
             restartButton.SetActive (true);
             menuButton.SetActive (true);
             gameObject.SetActive (false);
             Manager.SetActive (false);
             WinningImage.SetActive (false);
         }
     }
     void Update() {
         if(Input.GetMouseButtonDown(0)) {
             RaycastHit2D hit = Physics2D.Raycast(camMain.ScreenToWorldPoint(Input.mousePosition), Vector3.zero);
             if(hit) {
                 collisionObject cObj = hit.collider.GetComponent<collisionObject>();
                 if(cObj) CheckDestroyedIndex(cObj);
             }
         }
     }
 
 }


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

  • Sort: 
avatar image
0
Best Answer

Answer by polan31 · May 14, 2018 at 06:39 PM

The problem is solved. I added Awake and everything works.

Comment
Add comment · 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
0

Answer by ImpOfThePerverse · May 14, 2018 at 06:20 PM

Are you seeing the "Player hit object..." and "Yay you correctly hit..." debug text lines at start? If not, you might be forgetting to disable the buttons before pressing play. If you are seeing those lines, it might help you to know which collider is triggering the collision.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

86 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

Related Questions

I want to make text appear for a few seconds and then disappear. 2 Answers

How to get a 3D Text to appear on collision of another object? 2 Answers

Gui text script - help 1 Answer

[SOLVED] Why is text not appearing? 2 Answers

Text shows on Even numbers, then another text shows on Odd numbers. 0 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