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 /
  • Help Room /
avatar image
0
Question by faridphenom · Jul 27, 2018 at 05:35 PM · unity 5spriteproblem during runtime

Timer & if's

So, i have a really weird problem. i made a sprite array with 20 slot and i have a videoplayer in the scene. i want at some specified point of video, show one of the sprite in image that placed in the scene. but because my timer value change so fast, most of my conditions won't work because can't be detected so fast and i don't know how to fix it. Here's my code in Update function:

  string useSecond;
             foreach (VideoPlayer video in videos) {
                 useSecond = (video.time % 60).ToString ("f2");
                 show.text = useSecond;
                 if (useSecond == "6.73") {
                     showMoves.sprite = moves [1];
                 } else if (useSecond == "7.63") {
                     showMoves.sprite = moves [2];
                 }else if (useSecond == "8.67") {
                     showMoves.sprite = moves [3];
                 }else if (useSecond == "9.67") {
                     showMoves.sprite = moves [4];
                 }else if (useSecond == "10.67") {
                     showMoves.sprite = moves [5];
                 }else if (useSecond == "11.67") {
                     showMoves.sprite = moves [6];
                 }else if (useSecond == "12.23") {
                     showMoves.sprite = moves [7];
                 }else if (useSecond == "13.30") {
                     showMoves.sprite = moves [8];
                 }else if (useSecond == "14.20") {
                     showMoves.sprite = moves [9];
                 }else if (useSecond == "15.20") {
                     showMoves.sprite = moves [10];
                 }else if (useSecond == "16.30") {
                     showMoves.sprite = moves [11];
                 }else if (useSecond == "17.23") {
                     showMoves.sprite = moves [12];
                 }else if (useSecond == "17.87") {
                     showMoves.sprite = moves [13];
                 }else if (useSecond == "18.87") {
                     showMoves.sprite = moves [14];
                 }else if (useSecond == "20.03") {
                     showMoves.sprite = moves [15];
                 }else if (useSecond == "21.23") {
                     showMoves.sprite = moves [16];
                 }else if (useSecond == "22.37") {
                     showMoves.sprite = moves [17];
                 }else if (useSecond == "23.47") {
                     showMoves.sprite = moves [18];
                 }else if (useSecond == "23.50") {
                     showMoves.sprite = moves [19];
                 }
             }
 
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

Answer by tormentoarmagedoom · Jul 29, 2018 at 10:47 AM

Good day.

I'm sure there is a better option, but i did something similar in the past, and found and "easy solution".

As always want to have all the sprites in the same order, you can have all of them in scene all one over another

alt text

(But in exactly same position and commence all SetActive(false))

Placed in the inspector icheracy with the correct order, so you first see the move [1]

Then make the timer become a float value with float.Parse, so you can compare it.

And when time > 6.73f

you can SetActive(true) all of them . (the first sprite will be on top and you will se it)

Then when timer > 7.63f

You cand estroy ir SetActive(false) the first spritew. (So you will se second sprite)

And go doing SetActive(false) 1 by 1 when the time is > than the timer value.

Understand ?

Bye :D


sin-titulo.jpg (4.6 kB)
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 faridphenom · Jul 29, 2018 at 07:26 PM 0
Share

Thanks for answering but i solved it. it doesn't matter how i make conditions for time, it will always going to jump from one or two of my conditions. so i use the integer number of time and then invoke the function to show the right image for that time. if the time is 6 then i invoke the right function after 0.73sec. that's not good way for coding but it works for now and that is what i want. Thanks again.

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

202 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

Related Questions

How to change image sprite with text multiple times with button? 1 Answer

Sprite didn't change more than once 0 Answers

Windows 10 Unity Launcher Bugs at Sign In window 0 Answers

Sprite background 2 Answers

2D animation transitions and unexpected position changes 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