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 /
  • Help Room /
avatar image
0
Question by Pocknell-r251 · Jun 30, 2020 at 05:55 PM · scripting beginnervisual studio

Using FindObjectsOfType to create a randomise all features button on a character creator?,

I am a beginner at this, and am creating this project purely out of a desire to learn, if I've missed something that is commonly obvious and/or phrased this in the least efficient way, I apologise, please assume I know nothing.

I'm trying to create a character creation menu in unity. Things are going well so far, but I've decided I would like to add a button that randomises all the features of the character. I have managed to get one item to change randomly when the button is pressed, but not multiple. All items have the same script attached to them ("ChangingFeatures" script) and I am using this to tell the menu what to do when the button is pressed (pick something from a random range and change the sprite). To achieve this one item changing, I used FindObjectOfType(); which is great, and works fine, yay - one object achieved! Unfortunately this doesn't work to change all objects at once. I was told FindObjectsOfType would work but I don't understand how? My question is, is there a way to use FindObjectsOfType to change all of them at once, without having to go through and assign a different script to each item of clothing? This only returns an array and I'm not sure how that helps in changing the arrays in the ChangingFeatures script that store what item the character is wearing.

What I'm using to reference the feature

     private ChangingFeature changeFeature;
 
     private void Start()
     {
         changeFeature = FindObjectsOfType<ChangingFeature>();
     }

The start of the ChangingFeatures script, where the arrays are stored, I want to be able to change the feature, featureText, options, index, optionsText and textIndex all to the same thing, at the same time, across the board from every manager that holds the ChangingFeatures script when the Randomize button is pressed.

 public class ChangingFeature : MonoBehaviour
 {
     public SpriteRenderer feature;
     public Text featureText;
 
     public Sprite[] options;
     public int index;
 
     public string[] optionsText;
     public int textIndex;
 }




,

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
0
Best Answer

Answer by Pocknell-r251 · Jul 01, 2020 at 03:08 PM

I was doing this completely wrong. For anyone who might've stumbled across this who followed similar wrongness, check out this tutorial, the answer is to not use FindObjectOfType at all, but rather to use a list and to assign all your characters parts to that list. link text

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

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

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

Related Questions

unity visual studios not working properly 0 Answers

How do i combine a script from visual studio onto unity?,How do I add a script from visual studio to unity? 0 Answers

Finishing up my 2D quiz game [Last Problem] 0 Answers

Can some one Help me to convert bolt graph to c# script 0 Answers

New C# scripts used to derive from monobehavior but don't anymore,New scripts are not monobehaviours despite explicitly extending MonoBehaviour 2018.2.21f1 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