Log in or register to post comments

How to turn on/off multiple lights using GUI buttons in C# with imagetargets

February 26, 2013 - 11:53pm #1

Hi there, 

 Does anybody knows how to create guibutton switch for multiple lights in C# with out destroying it when loading a new scene.  For example, I have 1 GUI button which could be the switch that can be a toggle for on/off the lights. If I have 5 point lights in the scene, and 1 gui button that can control at once. And I also found some issue when using imagetargets all the lights are destroyed after the scene was reloaded. And right now I'm using an ipad 3 for testing. Can anyone help me with my problem. Any thing will do,  I just want to use for my simple AR project. Javascript or C# would be fine. Thanks. 

How to turn on/off multiple lights using GUI buttons in C# with

February 28, 2013 - 5:49am #7

Hi David, 

 

Now, its clear for me that all vuforia prefab are reinstantiated for each scene. Its working, but as repeat to go back over the scenes the gameobject's multiplies. Is there any way on how I can reset/restart my scene having only the number of gameobjects I had from the start? Thanks for helping me. 

 

Raymund  

How to turn on/off multiple lights using GUI buttons in C# with

February 27, 2013 - 3:37pm #6

Don't add your GUI script to a Vuforia prefab instance. Those are reinstantiated for each scene. Add it to a GameObject at the top level of your Hierarchy and use DontDestroyOnLoad.

 

using UnityEngine;
using System.Collections;

public class MyGUIScript : MonoBehaviour {
    void Awake() {
        DontDestroyOnLoad(transform.gameObject);
    }
}

 

How to turn on/off multiple lights using GUI buttons in C# with

February 27, 2013 - 3:08pm #5

Hi Nalin, 

 

The problem was when I turn on/off the switch for the first time the lights turns on/off but when I go back to main menu and go back again to my scene with lights, unity tells that a gameobject has been destroyed and keep on accessing it. I just need to toggle the switches again even I switch scenes. And does the imagetargets affects the "Dontdestroyonload" because it doesn't work anymore after I use the imagetargets for augmenting my scene? Ok, I'll just give a situation on what I'm doing: 5 spotlights, 2 directional lights, main menu scene, level 1 scene (this consist of those lights), 1 plane, imagetarget 

On the level 1 scene, I have 2 gui buttons the first one controls the 5 spotlights which can either turn on/off the switch. The other one controls  the 2 directional lights and do the same thing as well. If I go back to my main menu, and go back to my level 1 scene I should toggle the switches again. I guess that's it. Anyway thanks for your help.

 

Raymund

How to turn on/off multiple lights using GUI buttons in C# with

February 27, 2013 - 7:30am #4

but it's not really working

What isn't working?  What exactly is the problem?

N

How to turn on/off multiple lights using GUI buttons in C# with

February 27, 2013 - 7:09am #3

Hi Nalin, 

 

Yes, I'm using the Application.Loadlevel and also tried the Application.LoadLevelAdditive but it's not really working. I have 2 scene which is the main menu and the scene 1. What I want is to change level without destroying the lights. I want to turn on/off multiple lights using GUI buttons in C#. And Im using imagetargets for my AR project. Could you please show me some sample codes on how to do it. Thanks.

How to turn on/off multiple lights using GUI buttons in C# with

February 27, 2013 - 4:13am #2

Hi Raymund,

From your post it is not quite clear what the problem is.

It seems that you are loading an AR scene from some other scene.  Are you using  Application.LoadLevel  or Application.LoadLevelAdditive ?

Are your lights already in the AR scene?  If so, are you saying that those lights get destroyed after loading?
 
N

   

Log in or register to post comments