Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 netscool · Dec 21, 2016 at 07:35 AM · c#uicsdisable objectdisabling

SetActive (true); Used the wrong way?

So This is some easy code, depending on what button I press on my Canvas and each button represents different cars, like Audi, BMW and Special car! The value changes depending on the different buttons and the car models changes depending on the value

Button --[changes]--> Value --[changes]--> Car

Now I was testing the " GameObject.SetActive(true/false) " now I got a big issue the object does not change. Now the Value changes and the msg is sent out in the log. But the Game Object or the Car, in this case, doesn't change. But the Value does, the msg get printed. Which mean either two things > A: the engine is mishandling the request to make "cars" appear and disappear > or > B: There is another unknown script within my game that I have created that overwrites the decision. The thing is I checked and the only other script in the game is a level changer that reacts to another UI object, think it's related? Because I can't draw a correlation between them.

Now I build everything like it's done in this guide BTW: https://www.youtube.com/watch?v=kTDlCK4g-8A

using UnityEngine; using System.Collections;

 public class CarSelector : MonoBehaviour {
 
     public GameObject BMW;
     public GameObject AUD;
     public GameObject SPE;
 
     public int carSelected;
 
     void Start () {
 
         BMW.SetActive (true);
         AUD.SetActive (false);
         SPE.SetActive (false);
 
         carSelected = 1;
     }
     
     public void loadBMW () {
 
         BMW.SetActive(true);
         AUD.SetActive(false);
         SPE.SetActive(false);
         
         carSelected = 1;
         Debug.Log("car 1 was selected, BMW m4 n34");
     }
 
     public void loadAUD () {
 
         BMW.SetActive(false);
         AUD.SetActive(true);
         SPE.SetActive(false);
 
         carSelected = 2;
         Debug.Log("car 2 was selected, AUDI");
     }
 
     public void loadSPE () {
 
         BMW.SetActive(false);
         AUD.SetActive(false);
         SPE.SetActive(true);
 
         carSelected = 3;
         Debug.Log("car 3 was selected, Ferrari 250gt");
     }
 }
 





Here is my level changer, the weird part is that is that it work when changing scenes but can't disable/false objects on UI level

 using UnityEngine;
 using System.Collections;
 
 public class LevelLoader : MonoBehaviour
 {
 
     public GameObject Menu_Canvas;
     public GameObject settings_Canvas;
 
     void Start()
     {
 
         Menu_Canvas = GameObject.Find("MainMenu_Canvas");
         settings_Canvas = GameObject.Find("Settings_Canvas");
 
         settings_Canvas.SetActive(false);
         Menu_Canvas.SetActive(true);
     }
 
     public void LoadLevel(int a)
     {
 
         Application.LoadLevel(a);
     }
 
     public void Quit()
     {
 
         Application.Quit();
     }
 
     public void loadMenu()
     {
 
         Menu_Canvas.SetActive(true);
         settings_Canvas.SetActive(false);
     }
 
     public void loadSettings()
     {
 
         Menu_Canvas.SetActive(false);
         settings_Canvas.SetActive(true);
     }
 }


Thx for all the Answers - Love to improve this question // if it's answer destroy this post and send me there!

Comment
Add comment · Show 4
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 doublemax · Dec 21, 2016 at 08:32 AM 0
Share

I'm pretty sure that's not a bug in Unity, there must be something else going on.

From the code you've shown, one explanation could be that Start() gets called again for some reason. Put another Debug.Log in there to check.

avatar image UnityCoach · Dec 21, 2016 at 12:19 PM 0
Share

Do I understand that your GameObjects are not in the same scene as the UI? How do you link them then?

avatar image NoseKills · Dec 21, 2016 at 08:12 PM 0
Share

$$anonymous$$ake sure the car variables don't point to the same object and that there are no errors in the console.

avatar image netscool NoseKills · Dec 22, 2016 at 11:50 PM 0
Share

not very helpful, as I stated earlier I already check the variables and the syntax

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Geometrical · Dec 23, 2016 at 12:54 AM

Make sure that the car objects reference your cars in the scene (pre-instantiated game objects) and not the prefabs in the Unity Asset Database (the project's asset folder).

If that isn't the case then make sure the script in your editor matches the code-inspector in Unity of your script. Other than that the code seems fine and should do what it's intended to do.

Comment
Add comment · Show 1 · 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 netscool · Dec 24, 2016 at 11:21 PM 0
Share

I can't seem to find a solution so I am abandoning this project for now thanks anyway

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

13 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to animate RectTransform change in position 1 Answer

Options UI over all scenes 1 Answer

Render non-UI object next to a UI element on Screen Space - Overlay 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