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 TheCyberMan · Dec 09, 2011 at 01:53 AM · prefabobjectmenu

Accessing a Certain Script

Hello,

I am trying to create a "Back" button for my in-game login menu. The way it works so far is this: Menu > "Login" or "Update"

If you clicked "Login", it will do "Instantiate(LoginPrefab)"; if you clicked "Update", it will do "Instantiate(UpdatePrefab)". Simple.

I need a back button for both instantiated prefabs that will destroy the current instantiated prefab and then send the message "ActivateMenu, true" to a script called "crMenuScript.js" that is in the "Menu" prefab, the one where my menu runs from. ActivateMenu lets me use the menu again.

I've done multiple tests, but I can only destroy the instantiated prefab. I always get a "NullReferenceException" when trying to access "crMenuScript" from another prefab.

Forgive me for the newbish post, but I have tried everything I could do and find over the past couple weeks. All of Unity's scripting reference pages could not help me (perhaps I was using the scripts the wrong way).

Thank you very much,

TheCyberMan

P.S. I would prefer this to be in Javascript, but I just need guidance on getting this to work. I could translate the language to Javascript later if need be.

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 syclamoth · Dec 09, 2011 at 01:58 AM 0
Share

Why are you trying to delete the prefab? You shouldn't be able to do that in any case. I think you aren't doing this in a very good way- what do the objects with these various scripts on them do other than draw the menus? You could put all of these on a single object, and then enable/disable them when you need to.

avatar image TheCyberMan · Dec 09, 2011 at 02:05 AM 0
Share

The menu is a prefab itself. When I click the "Login" button, it instantiates a clone of the login system's prefab. I can't put the other prefabs inside of the menu prefab. I want to delete the prefab so that when I click "Back" it destroys the clone.

avatar image syclamoth · Dec 09, 2011 at 02:22 AM 0
Share

A prefab never 'executes' at runtime. I still don't understand why you can't just enable and disable the menus when you need to. I understand how the system works now, I just don't think it's a good method. You haven't given me a compelling reason why it has to work the way you are trying to do it. You can have many components on a single gameObject, and you can create and destroy those components at runtime easily.

avatar image TheCyberMan · Dec 09, 2011 at 02:37 AM 0
Share

"Login" and "Update" have two separate prefabs that activate when their respective button is clicked. What do you recommend I do then? This is very new for me.

Thank you.

1 Reply

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

Answer by Justin Warner · Dec 09, 2011 at 03:51 AM

Rather than do prefabs with different GUI stuff...

do something simliar:

 var showMain = true;
 var showLevels = false;
 var showOptions = false;
 var showExitSplash = false;
 
 
 function OnGUI()
 {
     if(showMain)
     //Show main GUI crap.
     //If (Button here for levels, if clicked do this down here.)
     //showMain = false; showLevels = true;
     if(showLevels)
     //Show level selection
     //If (Button here for back to main, if clicked do this down here.)
     //showMain = true; showLevels = false;
     if(showOptions)
     //Show options stuff
     //If (Button here for back to main, if clicked do this down here.)
     //showMain = true; showOptions = false;
     if(showExitSplash)
     //Do splash screen then exit
 }

That's how I do mine... Think of OnGUI as Update() so that it runs every frame, so if something is false, it won't do under that, if it's true it will. So then you can disable parts of your GUI, being kind of like layers.

=)

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 Justin Warner · Dec 09, 2011 at 03:52 AM 0
Share

By the way, if you need prefabs, then you can just Destroy(prefab1) before you change the boolean values, then it'll be good =).

avatar image TheCyberMan · Dec 09, 2011 at 07:56 AM 0
Share

I realize this is the better way to go, so I'm switching my menu system. Thank you for your time!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

What should a script contain? 1 Answer

How can I tell what prefabs a child object (script) is in? 2 Answers

Tagging object while instating not working. 3 Answers

When my prefabs are instantiated they don't have their script attached 1 Answer

script won't affect prefabs that were placed in the scene multiple times 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