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 noahmjohnson · Feb 14, 2011 at 04:40 PM · editor-scriptinglights

Change Point Light Values through Script

I am relatively new to scripting in Unity so this may be a question that requires more than I initially thought. I want to create an editor script that changes the values of a selected amount of point lights within a scene. For instance, I might want to change the intensity of 15 point lights from 1 to .35 without changing each individually.

I was going to use this bit of script as a jumping off point from the "How to Randomly Change the Intensity of a Point Light with a Script" thread, but I thought I would see if anyone else could point me in the right direction. http://answers.unity3d.com/questions/35577/how-to-randomly-change-the-intensity-of-a-point-light-with-a-script

EDIT : Maybe a more specific question is, how do I get a list of the point lights properties to display in the Editor Gui Layout and allow the user to change to the properties for all of the selected point lights? I have a simple Editor Script set up right now, but do not know how to draw a selected game objects properties. saltydog_nm 2 hours ago

Any help is appreciated!

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 noahmjohnson · Feb 17, 2011 at 05:35 PM

Here is the script I wrote after some poking around. Thanks for your help Dave.

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

using UnityEditor;

[RequireComponent(typeof(Light))]

public class BatchLightProperties : EditorWindow {

 int NumberofLights;

 List<Object> lightObjects = new List<Object>();

 Color lightColor = Color.white;

 float lightIntensity = 1f;

 float lightRange = 10f;



 // Add menu named "Batch Light Properties" to the Window menu

 [MenuItem ("Custom/Batch Light Properties")]

 static void Init () {

     // Get existing open window or if none, make a new one:

     BatchLightProperties window = (BatchLightProperties)EditorWindow.GetWindow (typeof (BatchLightProperties));

 }



 void OnGUI () {



     GUILayout.Label ("Light Properties", EditorStyles.boldLabel);

     NumberofLights = EditorGUILayout.IntField("No. of Lights", NumberofLights);



     for(int k = 0; k < NumberofLights; k++)

     {

         if(lightObjects.Count < NumberofLights)

         {

             lightObjects.Add(new Object()); 

         }

     }



     for(int j = 0; j < lightObjects.Count; j++)

     {

         lightObjects[j] = EditorGUILayout.ObjectField("Light: ",lightObjects[j],typeof(Object));    

     }



     EditorGUILayout.Separator();

     EditorGUILayout.Separator();



     lightRange = EditorGUILayout.FloatField("Light Range", lightRange);

     lightColor = EditorGUILayout.ColorField("Light Color", lightColor);

     lightIntensity = EditorGUILayout.Slider("Light Intensity", lightIntensity,0,8);     

 }



 void Update ()

 {

     foreach(Object obj in lightObjects){



         if(obj != null && obj.GetType() == typeof(GameObject))

         {

         GameObject lightGame = obj as GameObject;



         if (obj != null)

             {

             lightGame.light.color = lightColor;

             lightGame.light.range = lightRange;

             lightGame.light.intensity = lightIntensity;

             }       

         } 

     }





 }   

}

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
0

Answer by DaveA · Feb 14, 2011 at 05:26 PM

There are many scripts in the wiki that deal with altering multiple objects. The Asset Store has some nice things too. But if you want to write your own, take a look at this one to get some ideas:

http://www.unifycommunity.com/wiki/index.php?title=ReplaceSelection

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

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

EditorGUILayout - Use of unassigned local variable 2 Answers

Problem with OSX/Unity during long bake series (bug? workaround?) 0 Answers

Running a script when Unity starts. 3 Answers

How can i get the center of the entire editor window 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