- Home /
can't offset normal map
the offset of the normal map seems to be linked to the main texture, is normal map offset a pro only feature? or am I missing something here?
this is my code:
#pragma strict
//javascript
var Offset : Vector2;
var Speed : float = 0.1;
function Update () {
Offset = renderer.material.GetTextureOffset("_BumpMap");
Offset.y += Speed;
renderer.material.SetTextureOffset("_BumpMap", Offset);
}
I've tried changing it in the inspecor but that doesnt work either
Are you able to offset the main texture? Here's a sprite sheet animator I wrote that you can $$anonymous$$r apart if that helps... I know it scrolls through textures, though I haven't tried it with normal maps specifically. It's probably way more than what you're looking for, but maybe you can find what you need in there...
var sheetRows : float;
var sheetColumns : float;
var duration : float;
var curFrame : int = 1;
var incrementX : float;
var incrementY : float;
var loop : boolean = true;
var loopCount : int;
var animate : boolean = true;
var curRow : float = 1;
var curCol : float = 1;
var initialOffset : Vector2;
private var totalFrames : int;
private var animationStart : float;
private var lastFrame : float;
function Awake()
{
initialOffset = renderer.material.mainTextureOffset;
//renderer.material.mainTextureOffset.y = 1 - (1 / sheetColumns);
curFrame = 1;
curRow = 1;
curCol = 1;
if (duration <= 0)
{
duration = totalFrames;
}
if ((sheetRows > 0) && (sheetColumns > 0))
{
incrementX = 1 / (sheetRows);
incrementY = (1 / (sheetColumns)) * -1;
totalFrames = sheetRows * sheetColumns;
}
else
{
print ("Remember to set sprite sheet's column and row count.");
}
}
function Update()
{
if ((animate) && (Time.time >= lastFrame + (duration / totalFrames)))
{
advanceFrame();
}
}
function advanceFrame()
{
lastFrame = Time.time;
renderer.material.mainTextureOffset.x += incrementX;
curCol += 1;
curFrame += 1;
if (curCol > sheetColumns)
{
curCol = 1;
renderer.material.mainTextureOffset.x = 0;
renderer.material.mainTextureOffset.y += incrementY;
curRow += 1;
}
if (curFrame > totalFrames)
{
ResetOffset();
}
}
function ResetOffset()
{
renderer.material.mainTextureOffset = initialOffset;
curRow = 1;
curCol = 1;
curFrame = 1;
}
function playAnimation()
{
animationStart = Time.time;
animate = true;
}
function pauseAnimation()
{
animate = false;
}
function animationStop()
{
animate = false;
renderer.material.mainTextureOffset = initialOffset;
curFrame = 1;
}
Answer by Svyatoslav-Pilipenko · Feb 06 at 07:05 AM
На братан)
pragma strict
//javascript
var Offset : Vector2; var Speed : float = 0.1;
function Update () { Offset = GetComponent.().material.GetTextureOffset("_BumpMap"); Offset.x += Speed; GetComponent.().material.SetTextureOffset("_BumpMap", Offset); }