# How to make an object do a multiple tasks forever

I want to make an object rotate left (either a certain amount of degrees/for a certain amount of time, whichever is easier) then rotate right for time/degrees and have that repeat forever. How would I go about doing this?

Use My script

NOTE: Remember to fill in the required values in the inspector

There are clear tooltips that describes what you have to Add

``````//JS Javascript

#pragma strict

public enum AxisE{
x,
y,
z
}
public enum RotationE{
Right,
Left
}
@Tooltip("The axis the rotation should be in")
public var Axis:AxisE;
@Range(0,90)
@Tooltip("The Speed the object should move in")
public var RotationSpeed : float;
@Tooltip("The Object that will rotaate")
public var RotationObject : Transform;
@Tooltip("Maximum Right value the Rotation Object can turn to in degrees")
@Range(0,360)
public var MaxRight : float;
@Tooltip("Maximum Left value the Rotation Object can turn to in degrees")
@Range(0,360)
public var MaxLeft : float;
public var CurrentRotation : Vector3;
public var IsRotating : boolean;
public var Rotation : RotationE;

function FixedUpdate(){
CheckSetRotations();
}
function CheckSetRotations(){
CurrentRotation = RotationObject.eulerAngles;
if(Axis == AxisE.z){
RotateZ();
if(CurrentRotation.z > MaxRight){
Rotation = RotationE.Left;
}
if(-CurrentRotation.z > MaxLeft){
Rotation = RotationE.Right;
}
}
if(Axis == AxisE.y){
RotateY();
if(CurrentRotation.y > MaxRight){
Rotation = RotationE.Left;
}
if(-CurrentRotation.y > MaxLeft){
Rotation = RotationE.Right;
}
}
if(Axis == AxisE.x){
RotateX();
if(CurrentRotation.x > MaxRight){
Rotation = RotationE.Left;
}
if(-CurrentRotation.x > MaxLeft){
Rotation = RotationE.Right;
}
}
}
function RotateZ(){
IsRotating = true;
if(Rotation == RotationE.Right){
RotationObject.Rotate(0,0,RotationSpeed);
}
if(Rotation == RotationE.Left){
RotationObject.Rotate(0,0,-RotationSpeed);
}
IsRotating = false;
}
function RotateY(){
IsRotating = true;
if(Rotation == RotationE.Right){
RotationObject.Rotate(0,RotationSpeed,0);
}
if(Rotation == RotationE.Left){
RotationObject.Rotate(0,-RotationSpeed,0);
}
IsRotating = false;
}
function RotateX(){
IsRotating = true;
if(Rotation == RotationE.Right){
RotationObject.Rotate(-RotationSpeed,0,0);
}
if(Rotation == RotationE.Left){
RotationObject.Rotate(-RotationSpeed,0,0);
}
IsRotating = false;
}
``````