Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 tonyjoseph456 · Jul 04, 2015 at 09:53 AM · arraydeleteduplicateelementsfrom

Delete duplicate elements from an array in UnityScript

If you find my question as a duplicate question, please post the link to the answer also, I didn't find a proper solution to my problem here. That's why the question is asked below. My problem is given in the code below:

 var Speed1:float;
 var Speed2:float;
 var Speed3:float;
 var Speed4:float;
 
 var MaxStateTimer:float;
 var MinStateTimer:float;
 
 private var StateArray:Array;
 
 private var StateTimer:float;
 
 private var TaskValue1:float=70;
 private var TaskValue2:float=90;
 private var TaskValue3:float=100;
 private var TaskValue4:float=100;
 
 function Start()
 {
     StateArray=new Array();
     StateTimer=Random.Range(MinStateTimer,MaxStateTimer);
 }
 function Update()
 {
     TaskValue1=Speed1*Time.deltaTime;
     TaskValue2=Speed2*Time.deltaTime;
     TaskValue3=Speed3*Time.deltaTime;
     TaskValue4=Speed4*Time.deltaTime;
 
     StateTimer-=Time.deltaTime;
     if(StateTimer<=0)
     {
         StateTimer=Random.Range(MinStateTimer,MaxStateTimer);
         if(TaskValue1<=60)
         {
             //I need to add a number 1 to the array StateArray.
         }
         if(TaskValue2<=60)
         {
             //I need to add a number 2 to the array StateArray.
         }
         if(TaskValue3<=60)
         {
             //I need to add a number 3 to the Array StateArray.
         }
         if(TaskValue4<=60)
         {
             //I need to add a number 4 to the array StateArray.
         }
         //1) Now from these numbers in the array, I need to remove all the duplicate elemets in the array.
         //After removing duplicate elements, I need to randomly select a number from the list of numbers in the array StateArray
         // if the randomly selected number is 1, i have to do task1 if random number selected is 2 do task2 if random number selected is 3 do task3
         //
         
         //I tried several methods but all were giving errors. I need to know how to remove duplicate elements from the StateArray.
         //After removing duplicate numbers from the StateArray, ho do I select a random number from the Array.
 
     }
    
 }
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

1 Reply

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

Answer by fafase · Jul 04, 2015 at 10:04 AM

Simple way:

      bool a,b,c,d;

      if(TaskValue1<=60)
      {
          if(a == false){
              //I need to add a number 1 to the array StateArray.
              a = true;
          }
      }
      // Same for others with appropriate boolean.
Comment
Add comment · Show 4 · 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 tonyjoseph456 · Jul 04, 2015 at 10:51 AM 0
Share

Thanks for the answer. One more doubt, how to select a random number from the array StateArray?

avatar image fafase · Jul 04, 2015 at 11:48 AM 0
Share
  var item = StateArray[Random.Range(0, StateArray.Length - 1)];

If StateArray is a list then StateArray.Count - 1.

avatar image fafase · Jul 04, 2015 at 03:05 PM 0
Share

Yeah.....mmmmright....Let's see what you may have wrong there....Ah... got it, those two lines won't compile:

  "I'm new to Unity and I don't understand the working of code in Update function."

  "Because if I performed well, then only I will be getting a job in a company."
avatar image tonyjoseph456 · Jul 04, 2015 at 05:32 PM 0
Share

I had deleted my comment. Sorry..for that..

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

2 People are following this question.

avatar image avatar image

Related Questions

unique list of 10 random numbers 4 Answers

Clear 1 field of Transform array 1 Answer

How to delete new'd arrays? 2 Answers

Using class arrays for multiple Variables per element also Naming Elements 2 Answers

Duplication(instance) re-create deleted children 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