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 Creeper_Math · Dec 08, 2016 at 06:47 AM · c#arraystargetting

Auto-targetting script not working

I have this script that apparently isn't working. The goal of the script is to randomly select a target from an array of "allies" (or the player and player hirelings) in another script. What this script is supposed to do is go through each of the objects in the list of "allies", add the array location number to a local array (TargetsInLOS). This should result in a bunch of array location numbers in the TargetsInLOS, in which a random number from here is called and finally a return the number. The returned number should be the array location from the "Allies" list that is in the line of sight of the enemy.

Hopefully I commented enough to show my thinking / reasoning

 int GetTargetSelection() {
         int[] TargetsInLOS = new int[0]; // List of the target selections that will be filled with selection variables in line of sights
         int selection2 = 0; // Selection for each of the gameobjects for the "ForEach" part
         foreach (GameObject item in EntitiesDataBase.Allies) { 
             // The script below works, all it does is set LOS to true if there is a line of sight between the two vector3 positions
             CalculateLineOfSight(transform.position, item.transform.position);
             if (LOS == true) {
                 
                 // This works on another script, so hopefully this isn't the problem, but just incase...
                 // Stores the current variables of TargetInLOS into a storage array
                 int[] Storage = TargetsInLOS;
                 // Sets the TargetInLOS to a new array with a length of it's original length + 1
                 int var1 = TargetsInLOS.Length + 1;
                 TargetsInLOS = new int[var1];
                 //Replacing back the variables from storage into TargetInLOS
                 int selection = 0;
                 foreach (int item1 in Storage) {
                     TargetsInLOS.SetValue(item, selection);
                     selection += 1; // Setting it so the next item will go into the next array insert
                 }
                 TargetsInLOS.SetValue(selection2, TargetsInLOS.Length - 1); // Setting the final value to the selection of the original item that has a line of sight
                 
                 
             }
             selection2 += 1; // Setting is so the next item will go into the next array insert
         }
         int selection1 = Random.Range(0, TargetsInLOS.Length); //Picks a random number from the selection provided
         
         return (TargetsInLOS[selection1]); // Returns the selection of a random target that is "seen" by the enemy, which is used for aquiring the gameobject
     }


I don't really know anything Too Too advanced, and I don't really feel like changing the allies array to a list, as I already have it "infused" with all my other scripts

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 Creeper_Math · Dec 17, 2016 at 06:41 PM 0
Share

this script may actually be in working order, I found later that it was the Line of Sight calculator that was only working for just the player and not any other entitiy, so that was changed...

avatar image Fobri Creeper_Math · Dec 17, 2016 at 07:07 PM 0
Share

So does it work now?

avatar image Creeper_Math Fobri · Dec 17, 2016 at 07:09 PM 0
Share

So far it seems to work... the fine tuning now just needs to be done to the line of sight calculations...

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Failed setting triangles in my mesh 1 Answer

new Mesh() works outside of array, but not in array. Huh? 3 Answers

Vector3 resultant array sorting 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