Hi!
I’m creating a 2d endless runner game, where my character climbs a tower jumping from stone to stone. I wrote a code that repeats the tower texture and increase its offset velocity as you keep playing, and a code that keeps spawning the stones on the tower, but I couldn’t create a code that moves the stones from top to bottom at the same velocity of the tower, it’s desynchronized, I need to sync them to look like the stones are fixed to the tower (I’m using a rigidbody on the stones prefabs).
The script that is attached to the tower:
public float speed = 0.2f;
public float speedAux = 0f;
public Vector2 offset;
Renderer rend;
private void Awake()
{
rend = GetComponent<Renderer>();
}
void FixedUpdate()
{
offset = new Vector2 (0, Time.time * speed);
rend.material.mainTextureOffset = offset;
speedAux += 0.00001f;
if(speed < 0.5f){
speed += 0.00001f;
}
else if(speedAux > 0.5f && speed < 0.7f){
speed += 0.00001f;
}
}
I’ve tried a lot of things but couldn’t achieve the result I need, can somebody help me with that?