Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Vadom6 · May 14, 2019 at 06:25 AM · ontriggerenterontriggerexitontriggerstay

issues with on trigger enter and exit

So i have a seen set up where I have a flashlight object which you have to turn on and off to find clues, when you turn it on you have to leave the cone light trigger on the point of interest trigger for 5 seconds if you take it off before those 5 seconds it is meant to reset the timer, however if find when I move the flashlight trigger of manually it detects it and resets but when I turn the torch object off (which is what I intend for players to do) it doesn't recognize it as a trigger exit or anything, am I doing something wrong here? I am incredibly confused.

For a bit of clarity, I intend players to turn the torch off every time they stop using it and I want to make it so that the timer resets if you do, but the timer just keeps going anyway. ontriggerexit isn't working either is ontriggerstay.

edit:

The script is on the point of interest itself L_O_S is the line of sight of the torch.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Point_Of_Interest : MonoBehaviour
 {
 public GameObject Item_Dropped;
 public float waitTime = 5f;
 public bool isTriggered;
 // Start is called before the first frame update


 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "L_O_S")
     {
         Debug.Log("Object Triggered");
         isTriggered = true;
     }
 }
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == "L_O_S")
     {
         Debug.Log("Object Lost");
         isTriggered = false;
     }
    
 }

 private void Update()
 {
     if(isTriggered == true)
     {
         waitTime -= Time.deltaTime;
     }


     if(isTriggered == true && waitTime <= 0f)
     {
         Debug.Log("Object found");
         Destroy(gameObject);
     }

     if(isTriggered == false)
     {
         waitTime = 5f;
     }

 }

}

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 tormentoarmagedoom · May 14, 2019 at 07:57 AM

HEllo.

Post some code will help a lot :D Where is the script detecting the OntrIggeExit? Is in the torch? if is in the torch, is normal Ontriggerexit doesnt execute... the script is destroyed. (You can use OnDisable() and do exactly the same as OnTriggerEXit, this way when object is destroyed, its also called)

Bye!

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 Vadom6 · May 14, 2019 at 08:11 AM 0
Share

i have Updated the question, sorry about that.

avatar image tormentoarmagedoom Vadom6 · May 15, 2019 at 11:41 AM 0
Share

OnTriggerExit is beeing executed? or its inside the method that something doesnt work?

avatar image Vadom6 tormentoarmagedoom · May 16, 2019 at 06:02 AM 0
Share

it was neither, i've made it so that for a single frame the line of sight object is moved by 10000 on the z axis and then it runs the disable object code. the code now does what i want it to. thank you for your help though.

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

107 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

Related Questions

Check that an object is within the bounds of a trigger, but not touching them? 3 Answers

OntriggerEnter / Stay with the same Gameobject tags 0 Answers

Problem with OnTriggerEnter 1 Answer

OnTriggerStay/Enter/Exit 2 Answers

Have "OnTriggerStay" detection but only call it once? 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