Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PingPong : MonoBehaviour {
- public float distance;
- public float speed;
- float originalZ;
- // Use this for initialization
- void Start () {
- originalZ = this.transform.position.z;
- }
- // Update is called once per frame
- void Update () {
- if (this.transform.position.z > originalZ + distance) {
- speed *= -1;
- }
- if (this.transform.position.z < originalZ) {
- this.transform.position = new Vector3(this.transform.position.x,
- this.transform.position.y,
- originalZ);
- speed *= -1;
- }
- this.transform.Translate (Vector3.forward * speed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement