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 Azmakah · Oct 20, 2013 at 08:06 PM · collidertriggerplayerflashlight

When "Player" enters a trigger = flashlight off

Hey, I have a Flashlight script: var lightOfEpicness : Transform; var clickAudio : AudioClip;

 function Start () {
  
  lightOfEpicness.active = false;
  
 }
  
 function Update () {
         if(Input.GetKeyUp(KeyCode.F)){
                 audio.clip = clickAudio;
                 audio.Play();
                 if(lightOfEpicness.active == true){
                         lightOfEpicness.active = false;
                 } else {
                         lightOfEpicness.active = true;
                 }
         }
 }

and I want it so when I enter a trigger the flashlight goes off. I tried this but it didn't work. var Player : GameObject; var Script : FlashlightOff = Player.GetComponent("FlashlightOff");

     function OnTriggerEnter (other : Collider) {
    
     if(other.collider.tag == Player.tag)
    {
       Script = GetComponent(FlashlightOff);
       Script.enabled = false;
    }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TargonStudios · Oct 21, 2013 at 12:12 AM

You could try adding Static vars To the flashlight script, and setting the flashlight On/Off through a trigger script. For example.

This Script would go on a trigger collider:

 function OnTriggerEnter (other : Collider){
 if(other.gameObject.tag == "Player") {
 FlashLightScript.LightOn = false;
 }
 }

This Script would go on your flashlight (You will have to rename the script to "FlashLightScript" if you want it to work with the other script, or edit the other script for it to work):

    var lightOfEpicness : Transform;
 
     var clickAudio : AudioClip;
     
     static var LightOn = false;
 
 function Start () {
  
  lightOfEpicness.active = false;
  
 }


 function Update () {
 
 if(LightOn == false){
 LightOn = true;
 lightOfEpicness.active = false;
 }
 
         if(Input.GetKeyUp(KeyCode.F)){
                 audio.clip = clickAudio;
                 audio.Play();
                 if(lightOfEpicness.active == true){
                         lightOfEpicness.active = false;
                 } else {
                         lightOfEpicness.active = true;
                 }
         }
 }


Haven't tested it, but hope it helps.

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 Azmakah · Oct 21, 2013 at 04:11 AM 0
Share

Doesn't work for some reason. Nothing happens :/ But thanks for the answer!

avatar image TargonStudios · Oct 21, 2013 at 10:53 AM 0
Share

Did you rename your flashlight script?

avatar image TargonStudios · Oct 21, 2013 at 11:04 AM 0
Share

O$$anonymous$$ I fixed the problem, should work now.

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

16 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

Related Questions

Script works for NPCs, but not Player 1 Answer

Action activates trigger. 1 Answer

Can't click gameobject when over another trigger? 1 Answer

How to make trigger removes script. 1 Answer

How to make a box (or any object) appear on collide? 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