- Home /
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:
- 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. 
- 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.
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
Your answer
 
 
             Follow this Question
Related Questions
procedural texture uv error 0 Answers
Blender to Unity strange normal import problem (bright spots) 1 Answer
Delete Uv2 of a mesh? 1 Answer
Best way to atlas texture2Ds used on quads? 0 Answers
uv layout problem 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                