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 Tyrebear · Apr 25, 2014 at 01:52 AM · sceneprefabsartificial intelligencewaypoints

How can I make more than one AI entity prefab to move or activate?

Hi I have finally completed my own AI system for the customers in my game but I can only get it to work on one prefab in the scene. Even if I duplicate the customer prefab only one will move. I need the prefabs to act independently as well. How can I do this?

 var waypoint : Transform;
 var currentWaypoint : int;
 var agent : NavMeshAgent;
 var script1 : SlideOutMenu;
 var activeWaypoints : Transform[];
 var inactiveWaypoints : Transform[];
 var masterWaypoints : Transform[];
 var startMoving = false;
 var selectedMenuItem : int;
 var subtractedBurgers : int;
 var subtractedGlucks : int;
 var subtractedBopsters : int;
 
 function Awake(){
 agent = gameObject.GetComponent.<NavMeshAgent>();
 agent.speed = Random.Range(2.5, 5);
 script1 = gameObject.Find("GUIElements").GetComponent(SlideOutMenu);
 }
 
 function Start(){
 inactiveWaypoints[1] = masterWaypoints[1];
 inactiveWaypoints[2] = masterWaypoints[2];
 inactiveWaypoints[3] = masterWaypoints[3];
 inactiveWaypoints[4] = masterWaypoints[4];
 activeWaypoints[5] = masterWaypoints[5];
 inactiveWaypoints[6] = masterWaypoints[6];
 inactiveWaypoints[7] = masterWaypoints[7];
 inactiveWaypoints[8] = masterWaypoints[8];
 inactiveWaypoints[9] = masterWaypoints[9];
 inactiveWaypoints[10] = masterWaypoints[10];
 inactiveWaypoints[11] = masterWaypoints[11];
 inactiveWaypoints[12] = masterWaypoints[12];
 inactiveWaypoints[13] = masterWaypoints[13];
 }
 
 function Update () {
 TurnOnEntity();
 
 if(startMoving == true){
 waypoint = activeWaypoints[currentWaypoint];
 agent.SetDestination(waypoint.position);
 }
 }
 
 
 function OnTriggerExit(other : Collider){
 if (other.name == "0 Start"){
     currentWaypoint = Random.Range(2, 3);
     }
 }
  
 function OnTriggerEnter (other : Collider) {
 EatMeal();
 if (other.name == "0 Start"){
 currentWaypoint++;
 }
     if (other.name == "1"){
     script1.globalMoney += 50;
     WaitForSoda();
     }
         if (other.name == "2"){
         selectedMenuItem = Random.Range(1, 4);
         
         if(selectedMenuItem == 1 && script1.totalBurgers >= 1){
         subtractedBurgers += Random.Range(1, script1.totalBurgers);
         script1.totalBurgers -= subtractedBurgers;
         script1.globalMoney += subtractedBurgers * 10;
         subtractedBurgers = 0;
         }
         if(selectedMenuItem == 2 && script1.totalGlucks >= 1){
         subtractedGlucks += Random.Range(1, script1.totalGlucks);
         script1.totalGlucks -= subtractedGlucks;
         script1.globalMoney += subtractedGlucks * 15;
         }
         if(selectedMenuItem == 3 && script1.totalBopsters >= 1){
         subtractedBopsters += Random.Range(1, script1.totalBopsters);
         script1.totalBopsters -= subtractedBopsters;
         script1.globalMoney += subtractedBopsters * 20;
         }
         WaitForFood();
         }
     if (other.name == "4 End"){
     Destroy(gameObject);
     }
 }
 
 function WaitForSoda(){
 yield WaitForSeconds(2);
 if (activeWaypoints[3] == masterWaypoints[3]){
 currentWaypoint++;
 }
 if (activeWaypoints[12] == masterWaypoints[12]){
 currentWaypoint = Random.Range(12, 13);
 }
 if (activeWaypoints[6] == masterWaypoints[6]){
 currentWaypoint = Random.Range(6, 8);
 }
 if (activeWaypoints[9] == masterWaypoints[9]){
 currentWaypoint = Random.Range(9, 11);
 }
 }
 
 function WaitForFood(){
 yield WaitForSeconds(5);
 if (activeWaypoints[12] == masterWaypoints[12]){
 currentWaypoint = Random.Range(12, 13);
 }
 if (activeWaypoints[6] == masterWaypoints[6]){
 currentWaypoint = Random.Range(6, 8);
 }
 if (activeWaypoints[9] == masterWaypoints[9]){
 currentWaypoint = Random.Range(9, 11);
 }
 }
 
 function EatMeal(){
 if (currentWaypoint >= 6 && currentWaypoint <= 13){
 yield WaitForSeconds(Random.Range(6, 13));
 currentWaypoint = 5;
 }
 }
 
 function TurnOnEntity(){
 if (activeWaypoints[1] == masterWaypoints[1]){
 startMoving = true;
 }
 if (activeWaypoints[2] == masterWaypoints[2]){
 startMoving = true;
 }
 if (activeWaypoints[3] == masterWaypoints[3]){
 startMoving = true;
 }
 }
 
Comment
Add comment · Show 6
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 getyour411 · Apr 25, 2014 at 02:21 AM 0
Share

Is this script attached to all the prefabs? If these are prefabs, where's the instantiate and is it doing/setting anything?

avatar image Tyrebear · Apr 25, 2014 at 03:09 AM 0
Share

Yea this script is what controls the AI and it is attached to all prefabs. The instantiate is located on another script and when the player makes an upgrade a new customer is instantiated by cloning the existing prefab in the scene. The prefab will clone itself in the scene but wont update any of its values. Here is part of the script that controls the cloning

 var r_UpgradeObjects: GameObject[];
 var script : GlobalTime;
 var waypointScript : NavigateWaypoints;
 var customerObj : GameObject;
 var debt = false;
 var show$$anonymous$$enuPos : float[];
 var show$$anonymous$$enuSize : float[];
 
 
 
 function Update() {
 waypointScript = gameObject.FindWithTag("Player").GetComponent(NavigateWaypoints);
     if (global$$anonymous$$oney <= -100) {
         Application.LoadLevel(4);
     }
 }
 
     //Button Set 2
     if (b_SubsetButtons[1] == true) {
     //Table W/ Two Chairs
         if(b_HideButtonSet[0] == true){
             if (GUI.Button(buttonSet2Rect1, b_ButtonText[b_ButtonTextHolder]) && b_ButtonTextHolder == 0) {
                     waypointScript.inactiveWaypoints[12] != waypointScript.masterWaypoints[12];
                     waypointScript.activeWaypoints[12] = waypointScript.masterWaypoints[12];
                     waypointScript.inactiveWaypoints[13] != waypointScript.masterWaypoints[13];
                     waypointScript.activeWaypoints[13] = waypointScript.masterWaypoints[13];
                     
                     Instantiate(customerObj);
                     
                     global$$anonymous$$oney -= 40;
                     r_UpgradeObjects[0].SetActive(true);
                     b_ButtonTextHolder = 10;
                     b_HideButtonSet[0] = false;
                     }
                     }
avatar image getyour411 · Apr 25, 2014 at 03:22 AM 0
Share

Put some debug into TurnOnEntity to see if the 2nd clone/preab actually gets there and changes set$$anonymous$$oving = true

avatar image Tyrebear · Apr 25, 2014 at 03:49 AM 0
Share

The second prefab doesnt change any of its values and wont seek out waypoints. I presume this is because in my instatiate script its not detecting the clone. original prefabcloned prefab

capture.png (41.2 kB)
capture1.png (40.4 kB)
avatar image getyour411 · Apr 25, 2014 at 03:56 AM 0
Share

I don't see anything that's looking for children of "Customers" but there's a lot of code here and I might be missing it. If the clone needs to be a child of Customers, you can change your Instantiate to be

 newObj = Instantiate;
 newObj.transform.parent = Customers

and also if your scripts are looking for something named "Customer"

 newObj.name = "Customer" 

although then you have to be sure your scripts are thinking the name "Customer" is unique

Show more comments

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

20 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

Related Questions

Created Prefab of Canvas, Deleted Prefab and Canvas got erased as well 0 Answers

How can I make the AI in my game wait in lines? 1 Answer

How to talk about objects in the scene, not prefabs? 0 Answers

many prefabs. application Performance 1 Answer

Dont Destroy On Load Scene Return Problem 1 Answer


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