Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 callefreme · Apr 05, 2019 at 07:56 PM · transparencyuvuv mappingspritesheetquad

Sprite animation on quad with UV-coordinates

I need to animate a character sprite in a 3D environment. So far, I have created a Quad, on which I have put a material containing the (possibly malfunctioning) sprite sheet/atlas (.png). I have also attached the script below to the Quad. I have two major challenges:

  1. The spritesheet refuses to show up as transparent in-game. Inspecting the .png-file shows the collection of sprites with the proper transparent areas. The background is either grey or a smear of colors.

  2. I have modified the script below in many ways to change the quad's current sprite by using UV-coordinates, but I can't figure out how to make this work properly. As of now, nothing changes in-game no matter what I set the UV-coordinates to.

Any ideas on where I might've gone wrong? I must've read 100 articles on UV-mapping by now.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class UVQuadMapping : MonoBehaviour
 {
     public Rect face = new Rect(0f, 0f, 1f, 1f);
     private float _elapsedTime = 0;
     private Mesh mesh;
     private new Vector2[] UVs;
     private int faceIndex = 0;
 
     void Start()
     {
          mesh = transform.GetComponent<MeshFilter>().mesh as Mesh;
          Vector2[] UVs = new Vector2[mesh.uv.Length];
          UVs = mesh.uv;
          setUVs(faceIndex);
          mesh.uv = UVs;
     }
 
     void Update()
     {
         _elapsedTime += Time.deltaTime;
         if(_elapsedTime > 1f)
             _elapsedTime = 0;
         else
             return;
 
         setUVs(faceIndex++);
          mesh.uv = UVs;
     }
 
     void setUVs(int pOffset = 0)
     {
         UVs[0] = new Vector2(0, 0);
         UVs[1] = new Vector2(1, 0);
         UVs[2] = new Vector2(0, 1);
         UVs[3] = new Vector2(1, 1);
     }
 }



Thanks! Will gladly add more details if needed.

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

Answer by harshiths037 · Nov 22, 2020 at 08:09 AM

@callefreme Hey I am also trying to do this, can you suggest me some articles about this ,or tell me what to search in google because i am very new to unity

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

106 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

Related Questions

How do I generate a Sphere with proper UVs? 1 Answer

Best way to atlas texture2Ds used on quads? 0 Answers

Normalizing mesh UVS? 1 Answer

How to get texture UV tiling and offset in a Surface Shader? 2 Answers

stretched UV map in generated mesh 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