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 $$anonymous$$ · Jul 04, 2018 at 02:12 AM · aicoroutineresponse

AI script making unity no longer respond.

So, I have an AI script that is unfinnished, and I am currently trying to test to see if a force of ten is applyed to it.

But currently the whole script seems to make unity no longer respond.

So, I changed a method with a while loop inside it to a coroutine, (By this point I have two coroutines with while loops)

The issue persisted.

so here is the code in question, its the whole script just incase the issue is being caused by another bit of the script entirely.

So anyone know the issue? I am fairly new so it may be an obvious issue that I just missed.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 using UnityEngine.Audio;
 
 //AI
 public class EstherchildAI : MonoBehaviour
 {
     public GameObject sight;
     public GameObject Estherchild;
     public GameObject Player;
 
     private Rigidbody2D EsthyRigi;
 
     public float speed = 4; 
 
     public string DirectionToMove;
 
     
     
     public enum State 
     {
         Lurking,
         Chasing
     }
 
     public State state;
     private bool alive;
 
     bool playerDetected = false; 
 
     private void OnTriggerEnter2D(Collider2D coll)
     {
         if (coll.tag == "player")
         {
             PlayerHasBeenDetected();
             state = EstherchildAI.State.Chasing;
 
 
         }
 
     }
 
     void PlayerHasBeenDetected ()
     {
         playerDetected = true; 
     }
 
 
     private void Start()
     {
         EsthyRigi = Estherchild.GetComponent<Rigidbody2D>();
 
         state = EstherchildAI.State.Lurking;
         alive = true;
 
 
         StartCoroutine("FSM");
 
     }
 
     IEnumerator FSM()
     {
         while (alive)
         {
 
             switch (state)
             {
                 case State.Lurking:
 
                     StartCoroutine (Lurking(DirectionToMove));
                     break;
 
                 case State.Chasing:
 
                     Chasing();
                     break;
 
 
 
             }
         }
 
 
         yield return null;
         }
 
 
 
 
     IEnumerator Lurking ( string Direction) 
     {
         while (alive)
         {
             switch (Direction)
             {
                 case "Right":
                     
                     break;
 
                 case "Left":
                     EsthyRigi.AddForce(transform.forward * speed);
                     break;
             }
         }
         yield return null;
     }
 
  
 
     void Chasing ()
     {
         
     }
 
 }
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 $$anonymous$$ · Jul 04, 2018 at 02:42 AM

Managed to solve it on my own.

First line I put in every while loop inside a coroutine was yield return new WaitForSeconds(0.1f);

doing this seems to have fixed it!

Comment
Add comment · 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

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

151 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 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

OnTrigger Stay/Exit - Stay Overriding Exit 2 Answers

Update SetDestination only every 0.2s with coroutines ? 5 Answers

AI Coroutine or ScriptableObject ? 1 Answer

Character AI in ScriptableObjects? 1 Answer

How to start at a specific coroutine? 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