Unity code is a simple implementation and move around the object

UnityEngine the using;
the using the System.Collections;

// the Add Script to the this you want to Move The Platform.
mobile platform around //
public class MovingPlatform: MonoBehaviour {

@ Platform Movement Speed stage moving speed.
public a float Speed;

// This IS . the position where the platform will move the location of the mobile platform
public Transform MovePosition; // Create an empty position of the moving object as a

Private Vector3 the StartPosition;
Private Vector3 EndPosition;
Private OnTheMove BOOL;

// Initialization for the Use the this
void the Start () {
/ . / store the start and the end position Platform will move between these two points at both ends of the left and right storage position.
the StartPosition = this.transform.position;
EndPosition = MovePosition.position;
}

void FixedUpdate () {

float step = speed * Time.deltaTime;

if (OnTheMove == false) {
this.transform.position = Vector3.MoveTowards (this.transform.position, EndPosition, step);
}else{
this.transform.position = Vector3.MoveTowards (this.transform.position, StartPosition, step);
}

//When the platform reaches end. Start to go into other direction.
if (this.transform.position.x == EndPosition.x && this.transform.position.y == EndPosition.y && OnTheMove == false) {
OnTheMove = true;
}else if (this.transform.position.x == StartPosition.x && this.transform.position.y == StartPosition.y && OnTheMove == true) {
OnTheMove = false;
}
}



}
--------------------- 

Guess you like

Origin www.cnblogs.com/hyhy904/p/11329132.html