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 artsdcs · Dec 15, 2011 at 02:06 PM · lighteffectsnewflashlight

light switch

i have a torch with a point light attached and i use this script for turning it on and off:

function Update() {

if (Input.GetKeyDown("mouse 0")) {

 if (light.enabled == true)

     light.enabled = false;

     else

     light.enabled = true;

 }

}

For a fire effect i added a particle system but how do i make it that they both turn on when i press my left mousebutton and disapear when i release it?

Or just disapear when i press again. Evantualy i need both so i hope that you could help me.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Subhi · Dec 16, 2011 at 12:50 PM

this should work , choose if the game opject have a light component or a particle emmeter or both by chick them

var lightOk = true;

var particleEmitterOk = true;

function Update()

{

 if (Input.GetKey("mouse 0")) 

 {

     if(lightOk)

     {

     light.enabled = true;

     }

     if(particleEmitterOk)

     {

     particleEmitter.emit = true;

     }

 }

 else

 {

     if(lightOk)

     {

     light.enabled = false;

     }

     if(particleEmitterOk)

     {

     particleEmitter.emit = false;

     }

 }



}

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 artsdcs · Dec 16, 2011 at 12:55 PM 0
Share

it works! but only not for my particles could this be becouse is use a particle system ins$$anonymous$$d of an emitter?

avatar image Subhi · Dec 16, 2011 at 01:17 PM 0
Share

i edited the script on this answer try it

avatar image Subhi · Dec 16, 2011 at 01:35 PM 1
Share

you should add the script to the light object and the particle system object

avatar image Subhi · Dec 16, 2011 at 02:26 PM 1
Share

problem no 1 : uncheck the LightO$$anonymous$$ in the script in the particle system and uncheck the ParticleSystemO$$anonymous$$ in the script in the light problem no 2 : don't uncheck the Particle Renderer , uncheck the Emit option in the particle emitter

i think that was the problem

avatar image artsdcs · Dec 16, 2011 at 02:33 PM 1
Share

thank you for everything it works exacly how i wanted it!!

Show more comments
avatar image
0

Answer by Subhi · Dec 15, 2011 at 02:18 PM

Try this

function Update() {

if (Input.GetKeyDown("mouse 0")) {

if (light.enabled == true)

 light.enabled = false;
 particleEmitter.emit = false;

 else

 light.enabled = true;
 particleEmitter.emit = true;

} }

Comment
Add comment · Show 4 · 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 artsdcs · Dec 15, 2011 at 02:33 PM 0
Share

so i just add it to the object containing the light and the particles or the light with the particles??

BTW thank you for your time!

avatar image Subhi · Dec 15, 2011 at 02:50 PM 0
Share

add it to any thing containing a light and a particles , if you want to add it to an objects that contains just a light or just a particles i will give you the code

avatar image artsdcs · Dec 15, 2011 at 04:52 PM 0
Share

oke but it gives me 2 errors

Assets/on and off.js(11,1): BCE0044: expecting }, found 'else'.

and

Assets/on and off.js(15,3): BCE0044: expecting EOF, found '}'.

can that be fixed also how do i set both the light and the particles to be off by default?

oh and i called the script on and off.

avatar image Subhi · Dec 15, 2011 at 09:48 PM 0
Share

problem fixed with

function Update()

{

 if (Input.Get$$anonymous$$eyDown("mouse 0")) 

 {

     if (light.enabled == true)

     {

         light.enabled = false;

         particleEmitter.emit = false;

     }

     else

     {

         light.enabled = true;

         particleEmitter.emit = true;

     }

 }

}

if you want to turn them off by default go to the light component and turn the chick box off , on the particle particleEmitter turn the emit chick box off

avatar image
0

Answer by artsdcs · Dec 15, 2011 at 06:07 PM

sry but it doesn't work it gives me errors that say:

Assets/ParticleSwitch.js(11,1): BCE0044: expecting }, found 'else'.

and:

Assets/ParticleSwitch.js(15,3): BCE0044: expecting EOF, found '}'.

so i can't play it is there a solution to these errors? maybe some mistakes in the script??

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 artsdcs · Dec 16, 2011 at 01:33 AM

it works sort of if you put it like this:

function Update()

{

if (Input.GetKeyDown("mouse 0"))

{

if (light.enabled == true)

{

 light.enabled = false;

 particleEmitter.emit = false;

}

else

{

 light.enabled = true;

 particleEmitter.emit = true;

} }}

but then still when i attach it to the torch object it says there is no Light attached to it.

only if i put it on the light itself it works but not exactly how i would like it becouse it turns on when i click and off when i click again and i would like that if i release my mouse it turns off.

and the script wont do anything with my particles is that becouse i use a particle system?

becouse when i put the script on that to nothing still happens so did i do something wrong??

oh yeh im putting the story im working on of the game up on deviantart tomorrow i think.

i hope im not bothering since im realy bad at scripting myself and this is my first real game i try.

and if you're wondering why i want the mouse button like that is becouse the torch is more of a fire staff.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Does anyone know of some good scripting tutorials? 2 Answers

Flashlight shadow problem 0 Answers

create flashing light effect for ambulance 1 Answer

Problem with ligths! 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