Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Grady · Sep 28, 2011 at 11:24 PM · lightsorderblinkingflashing

Police flashing light script

Hey guys,

I have found scripts that allow you to make lights blink/flash in time etc... But I was wondering, is there a good way to make Police lights (the ones that would be on top of the car) or would i just have to use lots of different scripts on each light and change the flashing order manually

Thanks

-Grady

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
4
Best Answer

Answer by syclamoth · Sep 28, 2011 at 11:58 PM

You can assign a cubemap light cookie which is half black and half white around the central axis- this way you can get the sweeping lamp effect happening! Unfortunately it's a bit difficult to get the lamp itself to 'flash' nicely, but if you have a 'flare' object attached to the light, it is possible to fade it in and out using Mathf.Sin and some constants. (Sin is actually more appropriate than it usually is, here- see testure's comment about rotating lamps!)

Actually, the simplest cubemap would be totally black on two sides, and then totally white on the other two, and then for the top and bottom, just two intersecting diagonal lines and a checkerboard-pattern!

For the flashing, I would have a lens flare Object- then put a script like this

public LensFlare flare; public float rotSpeed; public float rotOffset; public float maxIntensity;

void Update() { float newIntensity = Mathf.Sin((Time.time rotSpeed) + (rotOffset Mathf.Deg2Rad)) * maxIntensity; flare.brightness = Mathf.Clamp(newIntensity, 0, maxIntensity); }

Given the correct bits and bobs assigned in the editor, this should allow you to make a nice-looking police flare!

This script will give you everything you need to change the timing of each individual lamp- by changing the offset value, you can make different lamps flash at different times.

If you want to, you can use the same basic code on a light as well- but, for lights I would recommend using the black-and-white cubemap instead (because it is more accurate, and would look better anyway).

EDIT: Whoops! I forgot what the brightness bit was called for lensflares! Fixed it now.

Comment
Add comment · Show 9 · 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 Grady · Sep 29, 2011 at 12:39 AM 0
Share

for some reason I keep getting this error:

Assets/flash.cs(1,18): error CS0116: A namespace can only contain types and namespace declarations

And the other one is, when i have a game object selected (preferably the parent for the flashing lights) i go Component > Rendering > Lens Flare. Does that mean that I attach that script above to the same game object that the lens flare is attached to?

avatar image syclamoth · Sep 29, 2011 at 01:10 PM 0
Share

Obviously, you need to put all of this inside a class! When you create a new script from the editor in the project window, don't delete the bit at the top about public class Whatever : $$anonymous$$onoBehaviour- it's kind of vital. You don't have to attach it to the same object, since the flare is assigned in the editor (you have to drag and drop it on to your script component). Flares are not one of the usual components, and so do not have an automatic lookup like transforms and rigidbodies do.

avatar image Grady · Sep 30, 2011 at 02:18 AM 0
Share

I used this script, with the beginning bits still in it like you said. (flareFlash.cs)

using UnityEngine; using System.Collections;

public class flareFlash : $$anonymous$$onoBehaviour {

 public LensFlare flare;

public float rotSpeed; public float rotOffset; public float maxIntensity;

void Update() { float newIntensity = $$anonymous$$athf.Sin((Time.time rotSpeed) + (rotOffset $$anonymous$$athf.Deg2Rad)) * maxIntensity; flare.intensity = $$anonymous$$athf.Clamp(newIntensity, 0, maxIntensity); }

 }

And now I get this error:

Assets/flareFlash.cs(16,11): error CS1061: Type UnityEngine.LensFlare' does not contain a definition for intensity' and no extension method intensity' of type UnityEngine.LensFlare' could be found (are you missing a using directive or an assembly reference?)

I seem to have a really bad thing with gettings errors :/

avatar image testure · Sep 30, 2011 at 03:25 AM 0
Share

LensFlare doesn't contain a definition for 'intensity', just like the error says...

Try 'brightness' ins$$anonymous$$d:

http://unity3d.com/support/documentation/ScriptReference/LensFlare.html

avatar image Grady · Sep 30, 2011 at 03:52 AM 0
Share

ahhhh thankyou testure!!!!! the script works now! thanks for your help both of you, but just curios, would it still be ok to use a couple of point lights to sort of show the source of where the supposed light is co$$anonymous$$g from, i.e. drawing the halo on the point light....?

Show more comments
avatar image
0

Answer by testure · Sep 28, 2011 at 11:25 PM

The easiest way to do it would be to parent your point lights around an empty game object and then just use the curve editor to make them rotate. No scripting required.. unless you want them to speed up/slow down or turn off/on, etc.

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 testure · Sep 28, 2011 at 11:27 PM 0
Share

also, you probably need to specify what type of effect you're looking for.. you're talking about flashing, but police lights don't necessarily "flash". The typical police light is just a rotating light inside a glass lens: http://www.youtube.com/watch?v=IdaNooVo3f8

avatar image Grady · Sep 29, 2011 at 12:07 AM 0
Share

yeah, your right about the rotating bit :)

I was thinking maybe a bit like, if you've ever played grand theft auto iv, the police cruiser lights in that, they way they sort of flash in that. Here is a video: http://www.youtube.com/watch?v=PxO$$anonymous$$s91atyg (just to note: that video is in slow motion at the beginning, so the police lights actually flash normal speed throughout the video. if you skip through to 1:50 you will see what i mean....!!)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make flashing/blinking/flickering lights? 1 Answer

Police Flashing Lights? 4 Answers

Light effects on collision 1 Answer

Make character flash when taking damage [SOLVED] 0 Answers

indestructible gameobject 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