- Home /
Question by
LeeDoSeon · Sep 22, 2017 at 05:31 AM ·
ipad2uvanimation
Texture SetTextureOffset not working in only ipad2. how to solve it?
I tested it in PC, Android, IPad2 Air, and very well working.
But, only IPad is not working...
So, How to solve this Problem?
Shader :
Shader "Custom/UVScrolling" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_ScrollXSpeed ("X Scroll Speed", float) = 0
_ScrollYSpeed ("Y Scroll Speed", float) = 0
}
SubShader {
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"DisableBatching" = "True"
}
Pass
{
Cull Off
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
fixed4 _Color;
float _IsUseSetOffset;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f o;
v2f vert(appdata_t v)
{
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord * _MainTex_ST.xy + _MainTex_ST.zw;
//o.color = v.color;
o.color = _Color;
return o;
}
fixed4 frag(v2f IN) : SV_Target
{
fixed2 uv_Tex = IN.texcoord;
/*fixed varX = _ScrollXSpeed * _Time;
fixed varY = _ScrollYSpeed * _Time;
uv_Tex = IN.texcoord + fixed2(varX, varY);*/
fixed4 col = tex2D(_MainTex, uv_Tex) * IN.color;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UVAnimationEffect : MonoBehaviour
{
UITexture tex;
UI2DSprite sp;
UISprite sp2;
public bool isUseDirectSetOffset;
public float animSpeed = 0.2f;
public float scrollSpeed = 5.0f;
// Use this for initialization
void Start () {
tex = GetComponent<UITexture>();
sp = GetComponent<UI2DSprite>();
if(isUseDirectSetOffset)
{
scrollSpeed = 0;
}
sp.onRender = (Material mat) =>
{
mat.SetFloat("_ScrollXSpeed", scrollSpeed);
};
}
// Update is called once per frame
void Update () {
if(isUseDirectSetOffset)
{
float offsetX = Time.time * animSpeed;
sp.onRender = (Material mat) =>
{
mat.SetTextureOffset("_MainTex", new Vector2(offsetX % 1, 0));
//mat.SetTextureScale("_MainTex", new Vector2(offsetX % 1, 1.0f));
};
//Debug.Log(offsetX % 1);
}
}
}
Please Help me .. TT
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612135348im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UV animations on particles systems through script 1 Answer
moving spot light change floor 0 Answers
Bone to uv 0 Answers
Ipad 2 lag 0 Answers
Can I use unity 3d as a component of UI in ipad app? 0 Answers