• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Finding a method by custom attribute and passing to a UI button 1 Answer

Smooth transition from 360 to 0 degrees 1 Answer

My scroll view always scrolls to the bottom automatically. 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges