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 TrackpadStudios · Aug 02, 2012 at 06:34 AM · timerflashlight

How to create. The most basic flashlight possible.

I'm making a survival horror game, and I'm trying to make it realistic. I'm using a spotlight parented to a 1st person controller. No physical flashing is used. I need to figure out a way to add a five minute timer to the spotlight (it's a short game) so once that time is up, you just wander around in the ark until you die. No extra batteries, no picking up the flashlight, just a spotlight timer, or any simple alternative. Anyone got any ideas I can use? edit Got it. I apologize for sounding so stupid, for whatever reason, everything I tried wasn't working. Almost all of my coding experience is in HTML, so it's like learning a new language.

Comment
Add comment · Show 1
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 Fattie · Aug 02, 2012 at 07:16 AM 0
Share

to make timers in Unity you use "Invoke" - it's very simple

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Adam-Buckner · Aug 02, 2012 at 07:53 AM

How are you turning on and off your light? Or have you set it the light's "enabled" state to "on" in the inspector?

If you look at the documentation for "light":

http://docs.unity3d.com/Documentation/ScriptReference/Light.html http://docs.unity3d.com/Documentation/Components/class-Light.html

When reading these pages, you should find information about "enabled" (which is turning a component "on" or "off" by either clicking the box in the inspector or setting the state to "true" or "false" in code.

An example of the code used would be:

 var myLight : Light;
 myLight.enabled = false;

For a timer, you should read up on "Time" in the docs:

http://docs.unity3d.com/Documentation/ScriptReference/Time.html

With this you can create a timer. I would suggest, for simplicity, updating the time counter in the "Update()" function.

And example of the code used would be:

 var myTimer : float;
 myTimer = myTimer + Time.deltaTime;

BUT: All of this being said... this is relatively trivial when it comes to doing things in Unity. This says to me that you could use a little more grounding in Unity and using the Unity engine. For that I would suggest a few things:

  • Visit the teaching section of the Forum and run a few of the tutorials listed there.

  • Visit the teaching section of the Forum and take one of the classes I present for Unity Technologies (free)

  • Visit the teaching section of the Forum and read up on "Getting Started with Coding for Unity"

  • Read the first page on the scripting reference and the basic subjects you find on the main page: http://docs.unity3d.com/Documentation/ScriptReference/index.html

All of these will give you a much better foundation in Unity and the Unity engine. Things like this will become easy, if not trivial.

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 Fattie · Aug 02, 2012 at 08:10 AM 0
Share

Angel, everything you say is correct and he should do what you say. However one thing...

"...create a timer. I would suggest, for simplicity, updating the time counter in the "Update()" function..."

that is not correct, Angel. For a timer, just use "invoke". It is extremely simple.

 Invoke("TurnOffLight", 300);  // turn off the light in 300 seconds

 function TurnOffLight()
 {
 // turn off the light here
 }

that's it - the only way to do it.

"Invoke" is the main and basic command used in program$$anonymous$$g video games. $$anonymous$$any video games are simply long lists of hundreds of Invoke commands.

avatar image Adam-Buckner ♦♦ · Aug 02, 2012 at 09:58 AM 0
Share

Yes, Fattie, you are correct. I was trying to keep the scope of the answer to something so basic that it was using the most common and familiar methods. Because so much code can go into Update(), and learning to increment a value is important, I chose Update() as my suggestion.

Looking up Invoke() is a good, tho' slightly more advanced, topic: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity and Playmaker - Flashlight Decrease Logic 0 Answers

How do you write a Pauseable-Timer Script in Unity JavaScript? 1 Answer

Flashlight timer 2 Answers

Flash light timer 1 Answer

Timer that stops at trigger 1 Answer


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