Hi there, world’s biggest noob back again…
I have an enemy that enters the screen and rotates as he does so… the rotation is done via sprite animation, though, it doesn’t ACTUALLY rotate.
He enters and rotates quickly, stops and animates/rotates slowly in order to shoot and then takes off quickly again. The following script I have kind of works but on the last phase the animation and speed are both really jerky… there seems to be some sort of conflict and I can’t work it out. Any help would be greatly appreciated!
private var fSpeed = -3;
private var uvAnimationTileX = 2; //Here you can place the number of columns of your sheet.
//The above sheet has 4
private var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet.
//The above sheet has 1
private var framesPerSecond = 10.0;
function FixedUpdate()
{
transform.Translate(fSpeed,0,0);
Phase01();
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
function Phase01()
{
yield WaitForSeconds(1.0);
fSpeed = 0; // Slow down to shoot.
framesPerSecond = 1.0;
Phase02();
}
function Phase02()
{
yield WaitForSeconds(5.0);
fSpeed = -3; // Speed up to leave screen
framesPerSecond = 10.0;
}