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 Nizzle83 · Mar 02, 2019 at 05:43 AM · uiscripting beginnerarrays

How to load different sprites on a panel based on player level

Hey all I cant post any code here because i don't know where to start. What i have so far is the xp and level logic set on a script so that the player will level up when reaching certain xp totals. All of that works perfectly. I also have a panel that loads up on button click. What im trying to do is to make the image different on the panel depending on the player level. So for example if player is level 1 and presses the "store" button it will load image 1 as the panel sprite (its a 2d game), then if the player is level 2 and presses the same button it will load image 2. Ive tried using arrays but dont know how to tie it to player level. Im not sure if i need to make a button manager script, how to get access to the player level on the player level script or really what the best direction is. Ive watched alot of tutorials and none of them show me what im trying to do. Happy to provide more information or anything you need to assist. I hope my objective is clear here. Thanks in advance to all. :D

Comment
Add comment · Show 1
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 Nizzle83 · Mar 02, 2019 at 05:47 AM 0
Share

Also i have a switch statement to control xp required for next level. Not sure if that is a suitable place to put button onClick event conditions or not and if that even works.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by highpockets · Mar 02, 2019 at 08:13 AM

I think the best solution here would be to make a public array or serialized field private array of playerLevImages[numberOfPlayerLevels], this should be on a script on the panel that you will be changing. Place the images via the editor and the code should look something like:

 int level = playerLevel;
 image = playerLevelImage;
 public image[] playerLevImages = new image[5]; //put quantity of levels
 playerLevelImage = playerLevImages[level - 1];
 this.image = playerLevelImage;



Comment
Add comment · Show 2 · 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 highpockets · Mar 02, 2019 at 08:14 AM 0
Share

Code not tested

avatar image Nizzle83 · Mar 02, 2019 at 04:18 PM 0
Share

Hey highpockets The code is definately in the correct direction but not quite there yet. Thanks for your help thus far. I have been able to get access to the currentLevel variable from my Level$$anonymous$$anager script so that part is all good. There are some problems with the playerLevelImage part. Ill add the code as it sits now and then the errors.

using UnityEngine.UI;

public class LevelImages : $$anonymous$$onoBehaviour { private int level = Level$$anonymous$$anager.currentLevel; Image = playerLevelImage; public Image[] playerLevImages = new Image[10]; playerLevelImage = playerLevelImage[level - 1]; this.Image = playerLevelImage;

 void Start()
 {
     
 }

the currentLevel is not an error as it is pulling from my Level$$anonymous$$anager script. The errors i am getting are all in the playerLevelImage part. What am i missing for this to work? there are 17 errors in total. = are wrong, one of the the ; is wrong after the [level - 1], and also that the name does not exist so i know i need to reference it somewhere. I have added the script to the panel and have no array to put images in so that feels like a logical place to start. Sorry for my noobness.

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

170 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

Related Questions

Variable Vs Array? 2 Answers

How to change specific material shared among specific children. 1 Answer

Click on two buttons one at a time to get an image 0 Answers

Need help writing script 1 Answer

Multiline Text wont stay in separate lines after I copy and paste it. 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