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 · Apr 06, 2018 at 01:47 AM · aiai problems

Help with AI script

I created a script where the object will spawn if it isn't looked at after a certain time it becomes hostile and chases the player.

{

private bool Attack;

private bool Spawned;

private Transform script; // Use this for initialization void Start () {

Spawned = false;

Attack = false; Starting1();

 }

 public void Starting1()
 {
     StartCoroutine(Wait());
 }

 public void Starting2()
 {
     GetComponent<Renderer>().enabled = true;
     StartCoroutine(Spawn());
 }
  
 public void Seen()
 {
     if (Spawned == true && Attack == false && GetComponent<Renderer>().enabled == true)
     {
         Debug.Log("Seen");
         Starting1();
     }
 }
 public void Attacking()
 {
     if(Spawned == false && Attack == true)
         {
         GetComponent<Aifollow>().enabled = true;
         Debug.Log("Attacking");
     }
 }
 // Update is called once per frame
 IEnumerator Spawn()
 {
     Spawned = true;
     Attack = false;
     yield return new WaitForSeconds(1);
     Attack = true;
     Spawned = false;
 }
 
 IEnumerator Wait()
 {
     GetComponent<Renderer>().enabled = false;
     yield return new WaitForSeconds(3);
     Starting2();
 }
   
 

}

The problem with the script if that it works fine until The Spawn Corutine is enabled. The object shows after 1 second yet i don't get a log showing that it's "Seen" when i am looking at it and I don't get a log showing that its "attacking" either. Any way to fix this?

Comment
Add comment · Show 3
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 Priyanka-Rajwanshi · Apr 06, 2018 at 06:05 AM 0
Share

The function Seen() and Attacking() have not been called anywhere. They need to be called somewhere in order for the debug to run. I think you can try calling "Attacking" in Spawn function()

 IEnumerator Spawn()
 {
     Spawned = true;
     Attack = false;
     yield return new WaitForSeconds(1);
     Attack = true;
     Spawned = false;
     Attacking();
 }
avatar image Kek_Kek Priyanka-Rajwanshi · Apr 06, 2018 at 04:10 PM 0
Share

I called Attacking() and Seen() in the spawn function and only Attacking() works not Seen()

  IEnumerator Spawn()
     {
         Seen();
         Spawned = true;
         Attack = false;
         yield return new WaitForSeconds(1);
         Attack = true;
         Spawned = false;
         Attacking();
     }
     
avatar image Priyanka-Rajwanshi Kek_Kek · Apr 06, 2018 at 04:23 PM 0
Share

Seen() doesn't work because Spawn = true and Attack = false have been called in the next line.

Also I think you need to write an algorithm to deter$$anonymous$$e when to call the Seen() method.

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

131 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

Related Questions

AI Player Jerky Movement - Overcoming Obstacle 0 Answers

Light detecting + Light lowers variable 2 Answers

How do I make an Active 3D AI Ragdoll like in this video? 1 Answer

Unity2D Check which direction the enemy AI is heading? 1 Answer

i am having problems with my neural network (made from scratch),I am creating a neural network, however, whenever i start it. it crashes 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