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 Kek_Kek · Mar 19, 2018 at 09:53 PM · disabling

Objects not disabling on second try

I created a script where if you enter a trigger and press 'e' your player body would be disabled after 5 seconds so a blink animation could play. Once those 5 seconds finish, the main camera which is a child of the parent body is disabled and another camera located under the bed is set active. Once under the bed, the player is able to turn his flashlight on and off by pressing 'f' and if he presses 'e' again, another 5-second animation plays and then the camera under the bed is disabled and the main camera is set active again. The script works fine for only one bed, however, i made 4 beds using the same script. If I went to bed 1 and pressed 'e', the script would work fine. If I went to bed 2 and press 'e' I would be able to go under the bed but if I press 'e' again, the animation won't play and the second camera won't be disabled.

Video showing it: https://www.youtube.com/watch?v=OcTdnLIbsiI

Script: {

 public GameObject Camera;
 public GameObject Camera2;
 public GameObject panel1;
 public GameObject panel2;
 public GameObject blink1;
 public GameObject blink2;
 public Animator _animator;
 public Animator _animator1;
 private bool _isUnderBed = false;
 private bool _isInsideTrigger = false;
 public int speed = 1;
 public GameObject body;
 // Use this for initialization
 void Start () {
     Camera.SetActive(true);
     Camera2.SetActive(false);
     panel1.SetActive(false);
     panel2.SetActive(false);
     blink1.SetActive(false);

 }

void OnTriggerEnter(Collider other) { if(other.tag == "Player") { _isInsideTrigger = true; panel1.SetActive(true); } } void OnTriggerExit(Collider other) { if(other.tag == "Player") { _isInsideTrigger = false; panel1.SetActive(false); }
}

 private bool Ispanel1Active
 {
     get
     {
         return panel1.activeInHierarchy;
     }
 }
 private bool Ispanel2Active
 {
     get
     {
         return panel2.activeInHierarchy;
     }
 }
 void UnderBed()
 {
    
     StartCoroutine(Blink());
 }
 IEnumerator Blink()
 {
     

     yield return new WaitForSeconds(speed);
    
     Camera.SetActive(false);
     Camera2.SetActive(true);
     panel2.SetActive(true);
   
 }
 void OutofBed()
 {
    
     StartCoroutine(End());
 }
 IEnumerator End()
 {
    
     yield return new WaitForSeconds(speed);
    
     Camera.SetActive(true);
     Camera2.SetActive(false);
     blink1.SetActive(false);
     body.SetActive(false);

 }
 // Update is called once per frame
 void Update()
 {
     if (Ispanel1Active && _isInsideTrigger)
     {
         if (Input.GetKeyDown(KeyCode.E))
         {
             
             panel1.SetActive(false);
             _isUnderBed = true;
             if (_isUnderBed)
             {
                 UnderBed();
                 blink1.SetActive(true);
                 blink2.SetActive(false);
                
               
             }

         }

     }
     if (Ispanel2Active && _isUnderBed)
     {
         if (Input.GetKeyDown(KeyCode.E))
         {
             panel2.SetActive(false);
             OutofBed();
             blink2.SetActive(true);
        
         }
     }

 }   

}

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

0 Replies

· Add your reply
  • Sort: 

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

74 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

Related Questions

how toDisable the FPSInputController. 1 Answer

unity 4.6 UI disabling click/touch detection on objects behind user interface 0 Answers

Why can't I disable multiple components? 1 Answer

Disabling SmoothMouseLook on pause (NullReferenceException) 3 Answers

How to prevent a script on a disabled object from firing? 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