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 Seventh Stealth · Jan 11, 2015 at 04:20 PM · javascriptai

GameController script has 3 separate phases - Alert Caution and Normal. As soon as Alert is activated it switches to normal which then switches to Caution. How do I fix this?

 //STATUSES AND TIMERS
 //
 var alert : boolean;
 var caution : boolean;
 var normal : boolean;
 var alertTimer : float = 30;
 var cautionTimer : float = 30;
 
 //CHASING
 var statusGUI : GUIText;
 var guardSpawn : Transform;
 
 //var enemy : GameObject;
 var enemyUnit : GameObject;
 var enemyAIScript : EnemyAI;
 var enemyHuntScript : EnemyHunt;
 
 function Start(){
 
 enemyUnit = GameObject.FindGameObjectWithTag("Enemy");
 enemyAIScript = enemyUnit.GetComponent.<EnemyAI>();
 enemyHuntScript = enemyUnit.GetComponent.<EnemyHunt>();
 
 
 alert = false;
 caution = false;
 normal = true;
 }
 
 function Update(){
 
 if(alert == true && alertTimer >= 0){
 print("alert");
         caution = false;
         normal = false;
         print("CAUTION");
         statusGUI.guiText.text = "ALERT : "+alertTimer;
         alertTimer -= Time.deltaTime;
         
 }else{
         //ALERT FINISHED
         //SWITCH TO CAUTION
             alert = false;
             normal = false;
             caution = true;
             statusGUI.guiText.text = "";
            }
            
            
            
            
 //CAUTION
 if(caution == true && cautionTimer >= 0){
         alert = false;
         normal = false;
         print("CAUTION");
         statusGUI.guiText.text = "CAUTION : "+cautionTimer;
         cautionTimer -= Time.deltaTime;
     
         }else{
         
         //
         alert = false;
         caution = false;
         normal = true;
         statusGUI.guiText.text = "";
 
         }
 
 //NORMAL
 if(normal == true){
 alert = false;
 caution = false;
 print("Normal");
 alertTimer = 30;
 cautionTimer = 30;
 
 statusGUI.guiText.text = "NORMAL";
 }
 
 
 }
 
 function ActivateAlert(){
 alert = true;
 }


Theres the script. Bit complex but oh well. This is whats meant to happen -- When alert becomes active( alert == true && alertTimer >= 0) the alertTimer counts down. When it reaches zero caution becomes true and then that counts down and then it hit's normal. It was working yesterday but now when alert is true normal immediately becomes true and then caution becomes true. So caution is the only phase that works at the moment. I can't figure out why(which is why I came here) and I'm a programming newb. Please help.

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

Answer by DwaynePritchett · Jan 11, 2015 at 05:03 PM

Try setting the alertTimer = 30 inside the ActivateAlert function as well. Assuming that you are calling it to start the whole thing off. I don't use javascript but something like this perhaps.

 #pragma strict
 
  //STATUSES AND TIMERS
 //
 var alert : boolean;
 var caution : boolean;
 var normal : boolean;
 var alertTimer : float;
 var cautionTimer : float;
 var alertTime : float = 30;
 var cautionTime : float 30;
 //CHASING
 var statusGUI : GUIText;
 var guardSpawn : Transform;
 //var enemy : GameObject;
 var enemyUnit : GameObject;
 var enemyAIScript : EnemyAI;
 var enemyHuntScript : EnemyHunt;
 function Start(){
 enemyUnit = GameObject.FindGameObjectWithTag("Enemy");
 enemyAIScript = enemyUnit.GetComponent.<EnemyAI>();
 enemyHuntScript = enemyUnit.GetComponent.<EnemyHunt>();
 alert = false;
 caution = false;
 normal = true;
 }
 function Update(){
 if(alert == true){
        if(alertTimer >= 0){
         print("alert");
         statusGUI.guiText.text = "ALERT : "+alertTimer;
         alertTimer -= Time.deltaTime;
     }else{
         //ALERT FINISHED
         //SWITCH TO CAUTION
         ActivateCaution();
         print("CAUTION");
         statusGUI.guiText.text = "";
     }
 }
 //CAUTION
 if(caution == true){ 
     if(cautionTimer >= 0){
         print("CAUTION");
         statusGUI.guiText.text = "CAUTION : "+cautionTimer;
         cautionTimer -= Time.deltaTime;
     }else{
         //
         alert = false;
         caution = false;
         normal = true;
         statusGUI.guiText.text = "";
     }
 }
 //NORMAL
 if(normal == true){
 alert = false;
 caution = false;
 print("Normal");
 alertTimer = 30;
 cautionTimer = 30;
 statusGUI.guiText.text = "NORMAL";
 }
 }
 function ActivateAlert(){
 alert = true;
 alertTimer = alertTime;
 caution = false;
 normal = false;
 }
 
 function ActivateCaution(){
 caution = true;
 cautionTimer = cautionTime;
 alert = false;
 normal = false;
 }



Note, I most likely made some errors because I don't use Unity Script. But, if you call Alert via that activate this should work in theory. Hope it helps.

Comment
Add comment · Show 2 · 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 Seventh Stealth · Jan 11, 2015 at 06:14 PM 0
Share

Thanks. I'll try it later and report back!

avatar image Seventh Stealth · Jan 12, 2015 at 06:53 PM 1
Share

It worked thanks man !

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

26 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

Related Questions

i can't set destination, using AI Navmesh via raycast 1 Answer

Player Health drops fast, how to pause after damage 0 Answers

Basic Enemy Javascript 0 Answers

AI walk through solid walls 1 Answer

Follow up to AI Pathfinding Question 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