- Home /
Question by
dhruva3 · Jul 12, 2015 at 02:04 PM ·
textureoffsettexture offset
Texture offset only on enemy death
I want to offset the texture only when an enemy dies. The code i have written makes the texture offset with a jerk. i need to have it smooth. here is the code that i have written
public float scrollSpeed;
private Vector2 savedOffset;
public static float ox;
public static float oy;
public static float x;
public static float y;
void Start () {
savedOffset = GetComponent<Renderer>().sharedMaterial.GetTextureOffset ("_MainTex");
}
void Update () {
y = Mathf.Repeat (Time.time * scrollSpeed, 1);
x = Mathf.Repeat (Time.time * scrollSpeed, 1);
Vector2 offset = new Vector2 (ox, oy);
GetComponent<Renderer> ().sharedMaterial.SetTextureOffset ("_MainTex", offset);
}
void OnDisable () {
GetComponent<Renderer>().sharedMaterial.SetTextureOffset ("_MainTex", savedOffset);
}
}
ox and oy are set by random range between the -x,x and -y,y when the enemy dies in the enemy script. Thanks for the help!
Comment