Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 El Maxo · May 15, 2015 at 10:43 AM · c#animationuigif

Translate and Update (from java to c# (4.6UI))

Hi Everyone,

I have found this java script code that basically plays a loop of images, my issue is that it hasn't been updated to support the new UI elements, I have limited knowledge of java script so I have attempted to do this in c#. Bellow is the original script and the second is my poor attempt at implementing it. Any help would be apreachetd. (my code doest work, it was just used to sudo code and block out how I thought I could achieve this)

 var frames : Texture[];
 var framesPerSecond = 10;
  
 function Update() {
     var index : int = (Time.time * framesPerSecond) % frames.Length;
     renderer.material.mainTexture = frames[index];
 }

my bad code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Animation : MonoBehaviour {
 
     public Image wheretoputit;
     public Image[] images;
     int fps = 10;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         float index = (Time.time * fps) % images.Length;
         wheretoputit.mainTexture = images [index];
     }
 }
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 HarshadK · May 15, 2015 at 11:00 AM

Instead of

 wheretoputit.mainTexture = images [index];

use:

 wheretoputit.sprite= images [index];
Comment
Add comment · Show 5 · 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 El Maxo · May 15, 2015 at 11:05 AM 0
Share

Thanks for the speedy respone. I have also ran into this issue on the line above :

Assets/Animation.cs(18,46): error CS0266: Cannot implicitly convert type float' to int'. An explicit conversion exists (are you missing a cast?)

avatar image HarshadK · May 15, 2015 at 11:13 AM 1
Share

Use int type for index rather than float as:

 int index = (int)((Time.time * fps) % images.Length);
avatar image El Maxo · May 15, 2015 at 01:20 PM 0
Share

I do have one last question although it may be another question, I was using an "eventAlphaThreshold" to be able to click through the transparent part of the button earlier, but now this isn't working with the sprite. How can I make sure I click on the sprite but not the transparent area?

avatar image HarshadK · May 15, 2015 at 01:29 PM 0
Share

From the page UI.Image.eventAlphaThreshold it states a method:

In order for lower values to work, the sprite used by the Image must have readable pixels. This can be achived by enabling Read/Write enabled in the advanced Texture Import Settings for the sprite and disabling atlassing for the sprite.

Try that.

avatar image El Maxo · May 15, 2015 at 01:56 PM 0
Share

That is enabled, I don't think there is a sprite.eventAlphaThreshold thought

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to prevent an animation from triggering more than on due to fast clicking? 2 Answers

How to keep an animation attached to gameobject 0 Answers

Can I make an animated sky box using a gif or mp4?,Can I make an animated skybox with a gif or an mp4 file? 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