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 TransformDemo : MonoBehaviour
- {
- bool positive = true;
- bool negative = true;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- float d = 1 * Time.deltaTime;
- Vector3 pos = transform.position;
- //Vector3 posNegative = transform.position;
- if (positive == true)
- {
- if(pos.x<1)
- pos.x += d;
- transform.position = pos;
- if (pos.x >= 1)
- {
- positive = false;
- }
- }
- if (positive == false)
- {
- pos.x -= d;
- transform.position = pos;
- if (pos.x <= -1)
- {
- positive = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement