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 sir_ver · May 09, 2019 at 09:27 AM · listsetactiverespawnkill

Agent killing and respanwning

I have 10 Agents in my scene and there are fighting 5 vs. 5 with guns. Im working with the ML-agents toolkit and I have to train these agents. I have a timer which counts from 60 to 0 and if the time is up all agents have to respawn and set to their original positions. But it is not working. Here is my code for killing and respawning the agents:

     //list for the 10 agents
     List<GameObject> listOfAgent = new List<GameObject>();
     List<GameObject> listOfCounterAgent = new List<GameObject>();
 
     //list for killed agents
     List<GameObject> removeListOfAgent = new List<GameObject>();
     List<GameObject> removeListOfCounterAgent = new List<GameObject>();
 
 private void Awake
 {
         //Inserting all agents to list
         listOfAgent.AddRange(GameObject.FindGameObjectsWithTag("agent"));
         Debug.Log("Anzahl der Agenten: "+ listOfAgent.Count);
 
         listOfCounterAgent.AddRange(GameObject.FindGameObjectsWithTag("counterAgent"));
         Debug.Log("Anzahl der CounterAgenten: " + listOfCounterAgent.Count);
 } 
 
     //Removing the agents from the list if they are dead and inserting them to removeList
     public void AgentDead(GameObject opponent)
     {
         if (listOfAgent.Contains(opponent))
         {
             listOfAgent.Remove(opponent);
             removeListOfAgent.Add(opponent);
         }
 
         Debug.Log(listOfAgent.Count + " Agenten sind übrig");
     }
 
    //here the same
     public void CounterAgentDead(GameObject opponent)
     {
         if (listOfCounterAgent.Contains(opponent))
         {
             listOfCounterAgent.Remove(opponent);
             removeListOfCounterAgent.Add(opponent);
         }
 
         Debug.Log(listOfCounterAgent.Count + "Counter Agenten sind übrig");
     }
 
     //check if all agents are dead
     public bool AreAgentsDead()
     {
         if (listOfAgent.Count <= 0)
         {
             // Alle Agenten sind tot!
             return true;
         }
         else
         {
             // Sie leben noch!
             return false;
         }
     }
 
     public bool AreCounterAgentsDead()
     {
         if (listOfCounterAgent.Count <= 0)
         {
             // Alle Counter Agenten sind tot!
             return true;
         }
         else
         {
             // Sie leben noch!
             return false;
         }
     }
 //if time is up, then call enemy and counterEnemy done
 public void TimeIsUpGM()
     {
         //time is at 0
         
              EnemyDone();
              CounterEnemyDone();
      }
 
 
 public void EnemyDone()
     {
          //set all agents to active
         SetEnemysActive();
         //listOfAgent.Clear();
         //removeListOfAgent.Clear();
 
         //add removed agents to original list
         for (int i = 0; i < removeListOfAgent.Count; i++)
             listOfAgent.Add(removeListOfAgent[i]);
 
         Debug.Log("Anzahl der Agenten: " + listOfAgent.Count);
 
         //set agents to done
         for (int i = 0; i < listOfAgent.Count; i++)
             listOfAgent[i].GetComponent<EnemyController>().Done();
     }
 
 public void CounterEnemyDone()
     {
 
         //SetCounterEnemiesNotActive();
         SetCounterEnemysActive();
 
         //listOfCounterAgent.Clear();
         //removeListOfCounterAgent.Clear();
 
 
         for(int i = 0; i < removeListOfCounterAgent.Count;i++)
             listOfCounterAgent.Add(removeListOfCounterAgent[i]);
 
         Debug.Log("Anzahl der Counter Agenten: " + listOfCounterAgent.Count);
 
         for (int i = 0; i < listOfCounterAgent.Count; i++)
             listOfCounterAgent[i].GetComponent<CounterEnemyController>().Done();
 
     }
 
 
  public void SetEnemysActive()
     {
         for (int i = 0; i < removeListOfAgent.Count; i++)
             removeListOfAgent[i].SetActive(true);
     }
 
     public void SetCounterEnemysActive()
     {
         for (int i = 0; i < removeListOfCounterAgent.Count; i++)
             removeListOfCounterAgent[i].SetActive(true);
     }

But this code is not working. When the time is up and no agent has died, then everything is normal. Count of agents and counterAgents are 5. But if someone dies and the time is up, then the died agent won't revive. It is so confusing. The counter goes then up to agent: 5 and counterAgent: 6 then next round agent:5 counterAgent:7

And the Done method is in an other class and calls AgentReset()

 public override void AgentReset()
 {
    
     gameObject.transform.position = spawnPoint.position;


     agentRB.velocity = Vector3.zero;
     agentRB.angularVelocity = Vector3.zero;
 }

I don't know how to solve this

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

108 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

Related Questions

A node in a childnode? 1 Answer

unity3d multiplayer respawn 2 Answers

Respawning player not working 2 Answers

Respawning gameobject not working c# 0 Answers

2D Platformer - How do I have objects that kill the player upon touch/cause respawn? 2 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