Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 aser133gaming · Jul 17, 2018 at 03:13 PM · script.gamedevelopmentflashlighthorror

How to make a flashlight which is ON after collect?

Hello! Im making horror game. I want to make a flashlight which will be ON (till the end of the game) after collecting it from shelf. I know how to make a normal flashlight (attach spotlight to player or something else) but i dont have any script for it etc etc. If u want u can link here free flashlight model too :P Thanks in advance :)

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 kog513 · Jul 17, 2018 at 03:58 PM

I'm new here but I got this simple idea , u creat two flashlights , one set it inactive at the start of the game and make it already attached to the player and the other one in the shelf or whatever u wanna put it , anyway add a bool variable to your player and add a methode which only functions if the bool is ture that sets the first flashlight to active .. one ore thing u can destroy the one you collected attach this script to your Character .

 public class FlashLight: MonoBehaviour {
 public GameObject FlashLight // the one attached to the player 
 private bool FlashLight_collected ;
     void Start() {
 FlashLight.SetActive(true) ;
 }
 void Update(){
    /* The following code means ones u collected the FlashLight the one attached to the player will be 
    set to active */
     if (FlashLight_collected &&  !FlashLight.active){
                FlashLight.SetActive(true) ;
        }
   }
 void OnTriggerEnter(Collider collider){
       if (collider.CompareTag("FlashLight")) {
        DestroyObject(collider.gameobject) ;
        FlashLight_collected  = true ;
       // you can improve it by setting a bool to true and once u r out of the colliders it set it to false and 
           add another methode which allows u to click on a specific key to collect that Flashlight
         }
  }

} I'm new as well and I'm not used to write stuff in the forum so I'm sorry if I wasnt clear enough or if I had some mistakes in the code . Try it ur self just copy the idea and make ur own code doesnt matter if it's unoptimized just try to understand and learn how to code . I'm like 18 days in unity and I never coded before , Only some python in the uni but I can apply most of my ideas now

Comment
Add comment · Show 3 · 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 aser133gaming · Jul 17, 2018 at 05:17 PM 0
Share

Yea man but im that type of newbie can u explain it more? xD

avatar image kog513 aser133gaming · Jul 17, 2018 at 06:05 PM 0
Share

Okay I'll do my best , think about it this way : U already have the flash light but u wont be able to use it until u collect another one , So the Idea is to set the one attached to u as inactive(like invisble and wont function) at the beginning of the game , and then when u collect one in game , u set it to active(visible and functions) .

-First creat a flashlight and make it a child to ur player , and set to inactive ( in the inspecter ) - creat another flashlight and position it wherever u want -now make a sphere collider and set it to trigger to the flashlight u will be collecting ,and give it a tag like "FlashLight" ( give it any tag u want ) -now creat a script and attach it to ur player So u need 2 variables : - GameObject FlashLight // the one attached to u since the game started so make it a public one and drag and drop ur flash light in it . - Bool CollectedFlashLight // which will decide if the FlashLight attached to u should be active or not now in the script creat a methode like this one :

 void FoundFlashLight(){
 if (collectedFlashLight && !FlashLight.active) {
 /* Just saying , if u dont know this : if u apply "!" to a bool variable that means setting it to the opposit value in this case u r checking if it's false (which means our flashlight , the one attached to ur player is not active)*/
 FlashLight.SetActive(true) ;
 }
 }

  • now we need to check if we collected the FlashLight or not by making OnTriggerEnter(Collider collider) methode this methode takes a Collider Variable as a parametre , the collider variable is whatever u collide with but if this collider is set to trigger this means u can enter in the collision range , sry I'm not a good explainer ..

so we need to add this code :

 void OnTriggerEnter(Collider collider){
 if (collider.CompareTag("FlashLight")) {
 // write the tag u attached to the flashlight u will be collecting 
 destroyObject(gameobject) ; // Since we no longer need it
 collectedFlashLight = true ; 
 }
 }

  • now the final step call the FoundFlashLight() methode in ur update finction ! and voila done I'm sry mate I wish I could contact u in a better way to explain the whole thing perfectly . but u need to check for OnCollisionEnter() , OnTriggerEnter , If , while , RayCast and the common variables like Collider , Collision , int , float , string , RayCastHit , Some Input methodes ect .. start slowly mate just search and write stuff in a paper try to Creat something through what u know , and try each time to invent new ideas from the same way of Coding , I'm Creating a Game and it's pretty awsome so far , even tho I'm not that good with coding and stuff , but I never copy others scripts .. if u want to contact me I may can help u learn how to code , but u need to be really patient and spend some time trying

avatar image aser133gaming kog513 · Jul 27, 2018 at 02:47 PM 0
Share

How can i contact with u?

avatar image
0

Answer by singingstranger · Jul 17, 2018 at 03:57 PM

I have never made this myself but perhaps if you made the condition of it being on or off attached to a bool? So basically:

void Start(){

lampon=false;

}

void Update(){ if (pickuplamp=true){ lampon=true; } } ?

Comment
Add comment · Show 1 · 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 aser133gaming · Jul 17, 2018 at 05:18 PM 0
Share

Yea man but im that type of newbie can u explain it more? xD

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

127 People are following this question.

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

Related Questions

Flashlight 1 Answer

I want to turn my flashlight on and off, while still maintaining the flicker effects. 3 Answers

iPhone game development help?? 1 Answer

How to actually make an objective to my game 1 Answer

Send Game Prototypes to Game Companies 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