STAY INFORMED
following content serves as a personal note and may lack complete accuracy or certainty.

Minimal-Mistakes instruction
Useful vscode Shortcut Keys
Unix Commands
npm Commands
Vim Commands
Git Note
Useful Figma Shortcut Keys

less than 1 minute read

Saw Blade

I want to make saw blade to rotate everytime.

public class SawBlade : MonoBehaviour
{
private float rotationAngle = 20f;

    void Start()
    {
        InvokeRepeating("Rotate", 0.05f, 0.05f);
    }

    void Rotate()
    {

        transform.Rotate(0, 0, rotationAngle);
    }
}

InvokeReating is called “Rotate” function every 50 milliseconds.

But if I add event collider, there is a problem.

Since this object rotates every 50 milliseconds, event object also rotates if I add event collider in the saw object. So I made empty object named SawObj and add saw blade object, event object, and so on in that.

Pace

public float[] targetPosX;
public float moveSpeed = 3f;
private int direction = 1;

Need two very end positions.

if (transform.position.x <= targetPosX[0]){
    direction = -1;
}
else if (transform.position.x >= targetPosX[1]){
    direction = 1;
}

If saw blade is attached targetPos which are very end, change the direction.

float move = transform.position.x - direction * moveSpeed * Time.deltaTime;
transform.position = new Vector2(move, transform.position.y);

It moves continuosly.