Created
June 27, 2017 04:51
-
-
Save blenderdeluxe/f84d5bcd6f2b1bfbe2b5369a76e5a8fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class MovementTarget : MonoBehaviour | |
{ | |
private Transform target; | |
private Vector3 startPos; | |
private Vector3 targetPos; | |
private Vector3 tempTargetPos; | |
private float speed = 2f; | |
// Use this for initialization | |
void Start() | |
{ | |
target = transform.FindChild("Target"); | |
startPos = transform.position; | |
targetPos = target.position; | |
tempTargetPos = targetPos; | |
target.parent = null; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
transform.position = Vector3.MoveTowards(transform.position, targetPos, speed * Time.deltaTime); | |
} | |
private void FixedUpdate() | |
{ | |
if( transform.position == targetPos) | |
{ | |
if(targetPos == tempTargetPos) | |
{ | |
targetPos = startPos; | |
} | |
else if(targetPos == startPos) | |
{ | |
targetPos = tempTargetPos; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment