http://blog.csdn.net/lcy0221/article/details/44040739
Method 1: Use Vector3.movetowards
[CSharp] view plain copy
- </pre><pre name="code" class="CSharp" >void Update ()
- {
- float step = speed * time.deltatime;
- GameObject.transform.localPosition = Vector3.movetowards (gameObject.transform.localPosition, new Vector3 (10,- 3, step);
- }
Method 2: Use interpolation
[CSharp] view plain copy
- void Update ()
- {
- float step = speed * time.deltatime;
- GameObject.transform.localPosition =New Vector3 (Mathf.lerp (gameobject.transform.localposition.x, ten, Step), Mathf.lerp (GAMEOBJECT.TRANSFORM.LOCALPOSITION.Y, -3, Step), Mathf.lerp (Gameobject.transform.localposition.z, 50, Step)); //Interpolation algorithms can also be
- }
Method 3: Use Itween
[CSharp] view plain copy
- Itween.moveto (M_uibgcamera, Itween.hash ("x", -20,
- "Y", -3,
- "Z",
- "Time", 1.0,
- "Islocal", true
- ));
Method 4: Use the co-process
[CSharp] view plain copy
- Startcoroutine (Movetoposition ());
[CSharp] view plain copy
- IEnumerator movetoposition ()
- {
- Gameobject M_uibgcamera = Gameobject.find ("Ui/fengmian/uibgcamera");
- While (m_UIbgCamera.transform.localPosition! = New Vector3 ( -5, -3,))
- {
- M_UIbgCamera.transform.localPosition = Vector3.movetowards (m_UIbgCamera.transform.localPosition, new Vector3 (- -3, Time.deltatime);
- Yield return 0;
- }
- }
"Go" unity four ways to move an object to a specified position