Advertisement
Guest User

scriptbalok

a guest
Dec 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class ScriptBalok : MonoBehaviour
  7. {
  8.     public bool Moved;
  9.     public bool Back;
  10.     public float JarakX, JarakY, JarakZ, Speed;
  11.     public Vector3 InitTarget, MoveTarget;
  12.    
  13.  
  14.    
  15.     // Start is called before the first frame update
  16.     void Start()
  17.     {
  18.         InitTarget = transform.position;
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.         MoveTarget = new Vector3(InitTarget.x + JarakX, InitTarget.y + JarakY, InitTarget.z + JarakZ);
  25.         if (Moved)
  26.         {
  27.             if(Vector3.Distance(transform.position, MoveTarget) > 0.01f)
  28.             {
  29.                 transform.position = Vector3.MoveTowards(transform.position, MoveTarget, Time.deltaTime * Speed);
  30.                 Back = true;
  31.             }
  32.            
  33.         }
  34.         else
  35.         {
  36.             if (Vector3.Distance(transform.position, InitTarget) > 0.01f)
  37.             {
  38.                 transform.position = Vector3.MoveTowards(transform.position, InitTarget, Time.deltaTime * Speed);
  39.                 Back = false;
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement