Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class SmoothMove : MonoBehaviour
- {
- private Vector3 target;
- public float speed=1f;
- private bool hasTarget = false;
- private Vector3 moveVector=new Vector3();
- private Vector3 startPosition;
- private float smooth = 0f;
- private float smoothSpeed;
- // Use this for initialization
- void Start ()
- {
- startPosition = transform.position;
- smoothSpeed = speed*0.1f;
- }
- void FixedUpdate()
- {
- if (hasTarget)
- if(smooth<=1f)
- {
- smooth += smoothSpeed;
- moveVector.x = Mathf.Lerp(startPosition.x, target.x, smooth);
- moveVector.y = Mathf.Lerp(startPosition.y, target.y, smooth);
- transform.position = moveVector;
- }
- }
- public void setTarget(Vector3 t)
- {
- target = t;
- hasTarget = true;
- smooth = 0f;
- }
- public void setSpeed(float s)
- {
- speed = s;
- smoothSpeed = s*0.1f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement