From Unify Community Wiki
Revision as of 17:01, 5 May 2006 by Aarku (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Author: Jonathan Czeck (aarku)


This script can be used ot make your GUI objects fly in and off the screen pleasingly. Simply use GameObject.SendMessage to tell all your GUI objects to move when you'd like them to.


Place this script on a GameObject. Adjust m_InPosition to be where you want the object located when "in" and similarly for m_OutPosition. If you reset the script, m_InPosition will update.

From another script, use GameObject.SendMessage to send a Fly message with a boolean variable indicating whether it should fly towards the in or out position.

C# - GUIFly.cs

<csharp>using UnityEngine; using System.Collections;

public class GUIFly : MonoBehaviour {

   public Vector3 m_InPosition;
   public Vector3 m_OutPosition;
   public float m_TravelTime = 0.5f;
   public float m_DelayToStartTravelingAfterMessageReceived = 0.1f;
   public bool m_StartWithInPosition = false;
   void Start ()
       transform.position = (m_StartWithInPosition) ? m_InPosition : m_OutPosition;
   IEnumerator Fly(bool flyIn)
       yield return new WaitForSeconds(m_DelayToStartTravelingAfterMessageReceived);
       Vector3 targetPosition = (flyIn) ? m_InPosition : m_OutPosition;
       float startTime = Time.time;
       while (Time.time < startTime + m_TravelTime)
           transform.position = Vector3.Lerp(transform.position, targetPosition, (Time.time - startTime) / m_TravelTime);          
           yield return 0;
       transform.position = targetPosition;
   void Reset()
       m_InPosition = transform.position;

} </csharp>

Personal tools