Advertisement
Guest User

Untitled

a guest
Oct 16th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SmoothMove : MonoBehaviour
  5. {
  6.  
  7.     private Vector3 target;
  8.     public float speed=1f;
  9.     private bool hasTarget = false;
  10.     private Vector3 moveVector=new Vector3();
  11.     private Vector3 startPosition;
  12.     private float smooth = 0f;
  13.     private float smoothSpeed;
  14.     // Use this for initialization
  15.     void Start ()
  16.     {
  17.         startPosition = transform.position;
  18.         smoothSpeed = speed*0.1f;
  19.     }
  20.  
  21.     void FixedUpdate()
  22.     {
  23.         if (hasTarget)
  24.         if(smooth<=1f)
  25.         {
  26.             smooth += smoothSpeed;
  27.             moveVector.x = Mathf.Lerp(startPosition.x, target.x, smooth);
  28.             moveVector.y = Mathf.Lerp(startPosition.y, target.y, smooth);
  29.             transform.position = moveVector;
  30.         }
  31.     }
  32.     public void setTarget(Vector3 t)
  33.     {
  34.         target = t;
  35.         hasTarget = true;
  36.         smooth = 0f;
  37.     }
  38.     public void setSpeed(float s)
  39.     {
  40.         speed = s;
  41.         smoothSpeed = s*0.1f;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement