Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ScriptBalok : MonoBehaviour
- {
- public bool Moved;
- public bool Back;
- public float JarakX, JarakY, JarakZ, Speed;
- public Vector3 InitTarget, MoveTarget;
- // Start is called before the first frame update
- void Start()
- {
- InitTarget = transform.position;
- }
- // Update is called once per frame
- void Update()
- {
- MoveTarget = new Vector3(InitTarget.x + JarakX, InitTarget.y + JarakY, InitTarget.z + JarakZ);
- if (Moved)
- {
- if(Vector3.Distance(transform.position, MoveTarget) > 0.01f)
- {
- transform.position = Vector3.MoveTowards(transform.position, MoveTarget, Time.deltaTime * Speed);
- Back = true;
- }
- }
- else
- {
- if (Vector3.Distance(transform.position, InitTarget) > 0.01f)
- {
- transform.position = Vector3.MoveTowards(transform.position, InitTarget, Time.deltaTime * Speed);
- Back = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement