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 Shindy117 · Feb 10, 2017 at 07:11 PM · triggerbooleanblock

Trigger won't read my Bool change

Hello there

First off I am making a block game where blocks stack till they hit a trigger I made at the top of the level. The blocks spawn above the trigger so I used a bool that changes after a set time. The trigger should recognize the true statement and do nothing, however if it detects false it ends the game.

So I am confused as to how I can make a trigger check a bool of a object that got instantiated.

Here is what I want my code to do:

When the object gets instantiated, it sees that my bool "isFalling" is true,

after a few seconds(falling time) it will automatically change to false.

If the trigger detects false at all it will call my game over code.

Here is my code for both scripts: Trigger Code: public class Boundary : MonoBehaviour {

     private GameController gameController;
     private ShootableBlock block;
 
     void Start()
     {
         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
 
         if(gameControllerObject != null)
         {
             gameController = gameControllerObject.GetComponent<GameController>();
         }
     }
 
     void OnTriggerEnter(Collider entity)
     {
         if(entity.CompareTag("Block") == false)
         {
             gameController.GameOver();
         }
     }
 }

Then my Block code(object being instantiated): public class ShootableBlock : MonoBehaviour {

 public int currentHealth;

 public int scoreValue;
 public float fallingTime;

 
 private GameController gameController;
 public bool isFalling;

 void Start()
 {
     StartCoroutine( IsNotFalling());

     GameObject gameControllerObject = GameObject.FindWithTag("GameController");

     if(gameControllerObject != null)
     {
         gameController = gameControllerObject.GetComponent<GameController>();
     }

     if(gameController == null)
     {
         Debug.Log("Can't find 'Game Controller' script");
     }
 }

 public void Damage(int damageAmount)
 {
     currentHealth -= damageAmount;

     if(currentHealth <= 0)
     {
         Destroy(gameObject);
         gameController.AddScore(scoreValue);
     }
 }

 IEnumerator IsNotFalling()
 {
     isFalling = true;

     yield return new WaitForSeconds(fallingTime);

     isFalling = false;
 }

}

Help is much needed thanks to anyone that helps.

Also not sure if I should use OnTriggerStay instead what do you guys think?

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
Best Answer

Answer by jdean300 · Feb 10, 2017 at 08:34 PM

In your OnTriggerEnter function:

 Block block = entity.gameObject.GetComponent<Block>();
 if (block == null || block.isFalling)
   return;
 else
   do game over stuff
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 Shindy117 · Feb 10, 2017 at 10:35 PM 0
Share

THAN$$anonymous$$ YOU you helped me on two of my questions and both worked!

God bless you!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Alternate between two Audio clips on collision 3 Answers

Animator bool = true on TriggerEnter? 0 Answers

when MainCamera enter a trigger 1 Answer

Prevent one from doing action if one is activated (C# UNITY) 1 Answer

UI button doesn't appear - c# 3 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