light activation with script

hi all, i’m a videogame environment designer. i’m usign unity to create a personal dynamic scene.
but i have a proboblem with scripts.

i created a cube with physics and i made 1st person controller to collide with it. now i want that player can push the cube near a alpha plane nd, doing that, it performs following actions:

  • the alpha plane must hide
  • a panel containing project info must pop up
  • a light (pre-created by me) must turn on to enlight my 3D model.

can anyone show me the way to do that? maybe with a script.

thanks mates :smile:

This might help you with the light problem:

http://www.unity3dstudent.com/2010/07/beginner-b17-tweaking-components-via-script/

hi!

with this:

light.enabled = true;

I a while back created a street light that would detect the time of day, used a texture to simulate the ballast of the light. So it would flicker when coming on over half a second. When it was time to turn it off, I used another texture to simulate the quick drop off then a slight glow over 2 seconds.

When it was struck by a vehicle… ( mostly because I can’t drive) it would shut it’s self off for a quarter of a second and then turn it’s self back on.

Lastly, if the lamp was busted off of it’s base, the whole thing would turn it’s self off (as above) but with a shower of sparks…

All with:

Texture2D.GetPixel()
Light.intensity
Light.color
Light.enabled

A bit more than your question,but there is so much you can do with lights.

ty rof reply,
i used the script but:

  • this example shows how to activate the light when the cube hits the floor…i need it activates when hitting an obect named “freccia”
  • i need also that the object “freccia” wil disappera on collision
  • and an object called “cartello” appears on collision
  • finally i had some kind of syntax error using the script shown in the video…dunno why

is there a way to make all this interactions work?

Try this. Attach this script to the cube that hits the floor. Drag the light you want to activate into the myLight variable in the inspector. Uncheck the “enabled” box on the light (the script will take care of that). Hope this helps.

var myLight : Light;

function OnCollisionEnter(hit : Collision)
{
if (hit.gameObject.name == "freccia")
{
Destroy (hit.gameObject);
myLight.enabled = true;
}
}

or if you want to destroy an object other than the one that’s been hit.

function OnCollisionEnter ()
{
Destroy (GameObject.Find("freccia"));
myLight.enabled = true;
}

Where did you want to instantiate Cartello? Did you want it to replace freccia? Or did you want it to appear somewhere else?

somewhere else. cartello is already placed and hidden. i only need it to appear

Yeah!!! it works great…ty
it you want to see the result visit http://www.mannoroth.altervista.org/veichles/Camaro/Camaro.html

I haven’t had time to try this, but if your object is already in the scene, you just need to turn the renderer on and off just like the light. Try adding:

GameObject.Find("cartello").renderer.enabled = true;

This would go inside the OnCollision function as well.

i tried it but seems to not work…anyway it goes well even without it…now i only have the problem to add some glow effect to cartello. it’s a FX reflective (glass) material but the text above looks transparent and cannot read on it, any suggestion to make the text inside glow?

I’ll work on it some more this evening. I thought I had this working, but perhaps not. Did you uncheck the renderer “enabled” box for cartello in the inspector? The script takes care of enabling it, but cartello should be invisible at first.

As for the glow, I’m not very good with shaders etc. Hopefully one of the more artistic people will help out here. There are self-illuminating shaders available in standard assets, but I haven’t tried them for text or even know if that would work. I’ll give it a try when I have a moment later today.

By the way, looked at your website. The game looks nice so far :slight_smile:

ye, but the animation of a 15k polygon model make the scene go scat…so i decided to turn off animation…
ty for the mmoment u were wery usefull to me :smile: