-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSwappedTextures.cs
More file actions
67 lines (63 loc) · 1.9 KB
/
SwappedTextures.cs
File metadata and controls
67 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SwappedTextures : MonoBehaviour {
public Texture2D swappedTexture = null;
private SpriteRenderer thisRenderer;
private void Awake()
{
thisRenderer = GetComponent<SpriteRenderer>();
if (thisRenderer)
{
Shader _swapShader = Shader.Find("Custom/SwapTwo");
if (!_swapShader)
{
Debug.LogError("You dont have shader... ");
}
else
{
Material _newMat = new Material(_swapShader);
thisRenderer.material = _newMat;
thisRenderer.material.SetTexture("_MainTex2", swappedTexture);
}
}
else
{
Debug.LogError("There is NO spriterenderer attached to gameobject " + this.name);
}
}
/// <summary>
/// this will swap our used animator texture to another one
/// </summary>
/// <param name="_toWhat"></param>
public void SwapTexture(Texture2D _toWhat)
{
swappedTexture = _toWhat;
if (thisRenderer)
{
Shader _swapShader = Shader.Find("Custom/SwapTwo");
if (!_swapShader)
{
Debug.LogError("You dont have shader... ");
}
else
{
Material _newMat = new Material(_swapShader);
thisRenderer.material = _newMat;
thisRenderer.material.SetTexture("_MainTex2", swappedTexture);
}
}
else
{
Debug.LogError("There is NO spriterenderer attached to gameobject " + this.name);
}
}
public void Update()
{
if (swappedTexture != null)
{
SwapTexture(swappedTexture);
swappedTexture = null;
}
}
}