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
1
Question by DrRocker87 · Sep 12, 2012 at 07:30 AM · objectslevelaccessadditive

Can I Access Objects or Scripts in an Additive Level?

I have a quick question, that maybe I can get some explanation on.

I currently have one level, which loads 3 additive levels. What I did was made my entire GUI out of additive levels, but I want to send notifications to that Additive level.

Is it possible to access a script running in an Additive Level from the Main Level that I loaded?

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

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

Answer by DrRocker87 · Sep 21, 2012 at 07:17 PM

@mikebelotti - Thanks! Didn't even think about that one.

For now, I just have the MainLevel finding the game object in the Additive Level by Name and calling its function:

 GameObject.Find("Manager_Tasks").GetComponent<TaskMgr>().AddTask(1);

I dont think there will be any major mix ups as long as I keep my naming structure intact.

Thanks for all the help everyone!

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
1

Answer by DaveA · Sep 12, 2012 at 07:43 AM

I dont see why not, have you tried it?

Comment
Add comment · Show 7 · 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 DrRocker87 · Sep 12, 2012 at 04:55 PM 0
Share

I have tried something like this.

In the Additive level I declare a public function in a script (Notification.cs):

public void SendNotification(string text){

}

In the $$anonymous$$ain Level I tried calling that script, but the way I usually call a different script doesnt work.

I usually use: object.GetComponent().SendNotification("Here");

But I wouldnt have access to an object would I?

avatar image DrRocker87 · Sep 13, 2012 at 12:03 AM 0
Share

Round two:

I have a public class attached to my additive level.

     public GUITexture Background;
     Vector3 StartPos;
     Vector3 EndPos;
     float i = 0.0f;
     
     public IEnumerator Transition()
     {
         StartPos = new Vector3(.1f, 1.0f, .2f);
         EndPos = new Vector3(.1f, .9f, .2f);
         
         float t = 10.0f;
         
         while (t < 1.0f)
         {
                 t += Time.deltaTime * (Time.timeScale/1.5f);
 
                 Background.transform.position = Vector3.Lerp(StartPos, EndPos, t);
             
                 yield return 0;
         }
     }

Now, I acces the script in the $$anonymous$$ain Level with a button:

 void Start(){
      PublicClass newPC = new PublicClass();
 }
 
 void OnGUI(){
    if(GUI.Button(new Rect(100,100,100,100), "Slide In")){
         StartCoroutine(newPC.Transition());
     }
 }

But when I do this, its making me declare and set the Background to the GUITexture. I have it setup in the Additive Level, why would i need to set it up again in the $$anonymous$$ain Level?

avatar image DrRocker87 · Sep 13, 2012 at 12:05 AM 0
Share

I think I am missing something here. I dont want to create a NEW class, I want to use the one that is was added in the Additive level.

avatar image DaveA · Sep 13, 2012 at 06:29 PM 0
Share

Hmm. This is where Javascript (UnityScript) may help because it can resolve things like that. C# likes to have things declared up front. So some thoughts:

  1. try Javascript or

  2. have your 'new' class be 'available' to the first level. Put it in Plugins folder or make a dummy object or something

  3. Use Send$$anonymous$$essage ins$$anonymous$$d of GetComponent

avatar image DrRocker87 · Sep 21, 2012 at 05:39 PM 0
Share

Ok, so I used the Send$$anonymous$$essage and did some reading on it, but its not working.

$$anonymous$$aybe I have something wrong.

So, in the "$$anonymous$$ain" level, lets say I have button that when clicked calls:

  Send$$anonymous$$essage("AddTask", "Task1", Send$$anonymous$$essageOptions.DontRequireReciever);

And in the 'Additive' Level I have a $$anonymous$$onobehavior Class called Task$$anonymous$$gr.cs that has a 'public' function 'AddTask(string task)' with a simple debug statement in it.

Shouldn't the Send$$anonymous$$essage go through all the current objects in the combined levels and find 'AddTask' and complete it? Or do I still have to define a GameObject to which I send to?

Any help would be appreciated.

Thanks!

Show more comments

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

11 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

Related Questions

Accessing other objects 2 Answers

How do you add levels to your game? 1 Answer

Converting object into script 1 Answer

Additively loaded scene in game remains in editor? 0 Answers

Accessing variables from another object? 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