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 DashAndStack · Jul 16, 2014 at 04:38 PM · bool

Change bool in an array from another script

Hi there,

I'm not exactly too great with scripting at the moment and I was wondering if I could get some help with something. I have used a free achievement manager script and I have trimmed it down quite small to the bits which I only need. The script allows me to create an array of achievements and assign a Name(string), Description(string), Complete Icon(texture), Incomplete Icon(texture), Earned state(bool).

I have made the earned bool state public so that when I press it in the inspector, naturally the Incomplete Icon changes into the Complete Icon.

I want to be able to do the said function above but from another script and implement it on for example a mouse click. I have used AchievementManagerAll.Earned = true; from the other script (AchievementManagerAll being the achievement manager script) and this works, except it changes ALL the achievements to true instead of just the one. What I want to do is tell my other script to JUST to turn on the Earned state for 1 particular achievement in the array.

So I guess the question would be, how would I change a bool value of an array element from another script? Would I have to do something along the lines of AchievementManagerAll.Earned("Test", true); ? <- I know that's wrong of course but you get the picture

I'll provide screenshots below. All help greatly appreciated.

-Connor

alt text alt text

array 1.png (128.6 kB)
array 2.png (21.7 kB)
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 robertbu · Jul 16, 2014 at 04:59 PM 0
Share

Giving you an exact answer would require seeing more code and having a full understanding of how you did your graphics and on what game objects all the scripts live. To get you started, let me list three ways that object communicate:

The primary way is GetComponent():

http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

http://unitygems.com/script-interaction1/

Send$$anonymous$$essage() is also used.

http://docs.unity3d.com/ScriptReference/GameObject.Send$$anonymous$$essage.html

And for C# you can use Events and Delegates:

http://answers.unity3d.com/questions/600416/how-do-delegates-and-events-work.html?sort=oldest

avatar image DashAndStack · Jul 16, 2014 at 05:20 PM 0
Share

solved, but cheers for the useful links mate :)

2 Replies

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

Answer by Jessespike · Jul 16, 2014 at 04:56 PM

Try adding something like this to AchievementManagerAll:

 public void SetEarnState(int index, bool newState)
 {
     Achievments[index].Earned = newState;
 }





Then try setting your earn state from a different script:

 AchivementManagerAll _AchivementManager = (AchivementManagerAll) GameObject.FindObjectOfType(typeof(AchivementManagerAll));
 _AchivementManager.SetEarnState(0, true);
Comment
Add comment · Show 1 · 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 DashAndStack · Jul 16, 2014 at 05:19 PM 0
Share

works awesome, thanks much :)

avatar image
0

Answer by aditya · Jul 16, 2014 at 05:46 PM

sadly it is true that this line is wrong AchievementManagerAll.Earned("Test", true);, because the variable Earned is not the member of class AchievementManagerAll but of AchievementAll but the class AchievementManagerAll contains a variable named Achievements of type Array means you should try something like this : AchievementManagerAll.Achievements[1].Earned = true;

the above line as pointing towards the SECOND element of the array as the indexing of an array starts from 0 like 0,1,2,3 and so on...

Hope this helps :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Click To Revert to Original Texture else Destroy script help 1 Answer

How to have animation play correctly 1 Answer

Need a bit of help with my script (about 100 lines) 1 Answer

Score System help 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