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 Moving_Object : MonoBehaviour
- {
- public GameObject objectToMove;
- public Transform start;
- public Transform end;
- public float moveSpeed;
- private Vector3 currentTarget;
- // Start is called before the first frame update
- void Start()
- {
- currentTarget = end.position;
- }
- // Update is called once per frame
- void Update()
- {
- objectToMove.transform.position = Vector3.MoveTowards(objectToMove.transform.position, currentTarget, moveSpeed * Time.deltaTime);
- if(objectToMove.transform.position == end.position)
- {
- currentTarget = start.position;
- }
- if(objectToMove.transform.position == start.position)
- {
- currentTarget = end.position;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement