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 Topthink · Aug 27, 2017 at 06:06 AM · listnavmeshnavmeshagentmovement scriptclass

How to Create a Unique Waypoint List for Each Prefab Unit ??

I wrote this C# script that creates a List of Vector3's for movement...My NavMeshAgent goes to the first location then the second and then the third and so on. As my agent gets there, it erases each waypoint (no longer needed) and when it gets to the last point, there is nothing left of the list...a simple dynamic list of vector3s. I can add more any time...as many as I wish.

It works fine. HOWEVER...

I was thinking that once I added this script to each of my prefabs, I would be able to provide each prefab with it's own unique list of waypoints so each of my prefab/navmeshagents could be controlled separately.

But, that's not how it works. ALL my nav mesh agents go to the same exact waypoints. I've been pulling my hair out trying to figure what to add to allow me to give separate waypoints to each prefab unit.

Any help to get my prefabs moving independently would be appreciated.

Thanks.

 public class TestNav1 : MonoBehaviour 
 {
 
     Collider sc;
     private bool isSelected = false;
     public NavMeshAgent agent;
 
     private int wayPoint = 0;
 
     public List<Vector3> moveToHere = new List <Vector3> ();
 
 
     void Update () 
     {
 
     //////////////////////////////////////////////////  Activates Unit   ///////////////////////////////////////////////////////////////////////////////////////////
         if (Input.GetMouseButtonDown (0))
         {
             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
              
             if (Physics.Raycast (ray, out hit))
             {
                 Collider sc = hit.collider;
 
                 if (sc.gameObject.tag == "Ally" || sc.gameObject.tag == "Supply")
                 {
                     GameObject[] tempGo;  ////////////////////////////////////////////////////// Next lines through the foreach statement changes color of nonselected items back to blue.  
                     tempGo = GameObject.FindGameObjectsWithTag ("Ally");
                     foreach (GameObject Ally in tempGo) 
                     {
                         gameObject.GetComponent<Renderer> ().material.color = Color.blue;
                         isSelected = false;
                     }
 
                     sc.gameObject.GetComponent<Renderer> ().material.color = Color.cyan;
                     agent = sc.GetComponent<NavMeshAgent> ();
                     isSelected = true;
                 }
             }
         }        //////////   End Unit Selection/activation Logic   ////////////////////////////////////////////////////////////////////////////
 
 
         /////////////////////////////////////////////////////////////    Begin Area where you "Click" to add way points.   ////////////////////////////////////////////////////////
         if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(1) && isSelected == true )
         {
             RaycastHit hit;
             if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
             {
 
                 moveToHere.Add(hit.point);
     
             }
         }////////////////////////////////////////////////////////////////////   End Click to add waypoint area   //////////////////////////////////////////////////////////////////
 
 
 
         if(moveToHere.Count>0) agent.destination = moveToHere [0];
 
         if (moveToHere.Count>0 && !agent.pathPending && agent.remainingDistance < 0.5f) moveToHere.RemoveAt (0);
 
 
 
     }
 
 }


 
Comment
Add comment · Show 2
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 Topthink · Aug 27, 2017 at 06:35 PM 0
Share

I'm still working on this...hoping to find a way to create a unique list for each prefab.

avatar image Topthink · Aug 28, 2017 at 02:54 AM 0
Share

I haven't figured out how to do this. I can't do much until tomorrow but I'll be back on then and try to research some more Internet information.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Topthink · Sep 14, 2017 at 10:32 PM

I think I finally figured this out through trial and error...I had been doing a few things wrong and I think I finally got it straightened out.

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
avatar image
0

Answer by hexagonius · Aug 27, 2017 at 06:33 AM

It depends on how you place them in the world. If the prefabs are created during edit mode you can just edit each prefab individually and that's it (just don't apply the changes).
If you instantiate them, the instantiator needs to set the waypoints.

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 Topthink · Aug 27, 2017 at 03:40 PM 0
Share

Thank you for your help.

The prefabs are spawned (instantiated) occasionally over a period of time. I don't want the waypoints to be assigned until AFTER they are created. Once the prefabs are created, I want to see what is going on in the world (on the terrain map) and then manually send them to different places...I might want to send them to a half dozen different places (thus the dynamic list).

But, I want to send each prefab to a different set of waypoints...and that is the problem. Right now, they all want to go to the same places.

Right now, I'm trying to fully interpret your response and I'll continue to look for a resolution. I do appreciate the time you took to help me.

avatar image Topthink · Aug 27, 2017 at 03:44 PM 0
Share

I've been looking at equipment lists (and so forth) that some people use for RPG games. I suppose you can make a comparison to something like that because each "character" needs a different set of equipment.

Anyway, I'm looking at different models that designers use to see if there is something there that I can use.

Again, thanks.

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

71 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

Related Questions

A node in a childnode? 1 Answer

Increase size of obstacle - navmesh 1 Answer

NavMeshPath.corners.length is always 0 1 Answer

Removing 100ms Delay in NavMeshAgent moving to destination? 1 Answer

How to access/print parts of a list 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