Last active
January 30, 2016 13:09
-
-
Save windwp/664e7f0a79682e326dcc to your computer and use it in GitHub Desktop.
unity get angle and rotatioin by speed
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
iTween.ValueTo(_maskPanel.gameObject, iTween.Hash( | |
"onupdate", "_showMaskEffSizeDelta", | |
"from", Vector2.zero, | |
"to", new Vector2(1200, 1200), | |
"easetype", iTween.EaseType.easeInCirc, | |
"onupdatetarget", this.gameObject, | |
"time", timeOfEffect | |
)); | |
iTween.ValueTo(_maskPanel.gameObject, iTween.Hash( | |
"onupdate", "_showMaskEffPosition", | |
"from", _rectMaskPanel.anchoredPosition, | |
"to", Vector2.zero, | |
"easetype", iTween.EaseType.easeInCirc, | |
"time", timeOfEffect, | |
"onupdatetarget", this.gameObject, | |
"oncomplete", "ShowGame" | |
)); |
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
//unity get angle and rotatioin by speed | |
float targetAngle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg; | |
transform.rotation = Quaternion.Slerp( transform.rotation, Quaternion.Euler( 0, 0, targetAngle ), turnSpeed * Time.deltaTime ); | |
//mathf functoin | |
//http://wiki.unity3d.com/index.php/3d_Math_functions | |
#region TriggerEventsSetup | |
// Use listener with no parameters | |
private void AddEventTrigger(UnityAction action, EventTriggerType triggerType) | |
{ | |
// Create a nee TriggerEvent and add a listener | |
EventTrigger.TriggerEvent trigger = new EventTrigger.TriggerEvent(); | |
trigger.AddListener((eventData) => action()); // ignore event data | |
// Create and initialise EventTrigger.Entry using the created TriggerEvent | |
EventTrigger.Entry entry = new EventTrigger.Entry() { callback = trigger, eventID = triggerType }; | |
// Add the EventTrigger.Entry to delegates list on the EventTrigger | |
eventTrigger.delegates.Add(entry); | |
} | |
// Use listener that uses the BaseEventData passed to the Trigger | |
private void AddEventTrigger(UnityAction<BaseEventData> action, EventTriggerType triggerType) | |
{ | |
// Create a nee TriggerEvent and add a listener | |
EventTrigger.TriggerEvent trigger = new EventTrigger.TriggerEvent(); | |
trigger.AddListener((eventData) => action(eventData)); // capture and pass the event data to the listener | |
// Create and initialise EventTrigger.Entry using the created TriggerEvent | |
EventTrigger.Entry entry = new EventTrigger.Entry() { callback = trigger, eventID = triggerType }; | |
// Add the EventTrigger.Entry to delegates list on the EventTrigger | |
eventTrigger.delegates.Add(entry); | |
} | |
// Use listener that uses additional argument | |
private void AddEventTrigger(UnityAction<Toggle> action, EventTriggerType triggerType, Toggle toggle) | |
{ | |
// Create a nee TriggerEvent and add a listener | |
EventTrigger.TriggerEvent trigger = new EventTrigger.TriggerEvent(); | |
trigger.AddListener((eventData) => action(toggle)); // pass additonal argument to the listener | |
// Create and initialise EventTrigger.Entry using the created TriggerEvent | |
EventTrigger.Entry entry = new EventTrigger.Entry() { callback = trigger, eventID = triggerType }; | |
// Add the EventTrigger.Entry to delegates list on the EventTrigger | |
eventTrigger.delegates.Add(entry); | |
} | |
#endregion | |
// singletion | |
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour | |
{ | |
protected static T instance; | |
/** | |
Returns the instance of this singleton. | |
*/ | |
public static T Instance | |
{ | |
get | |
{ | |
if(instance == null) | |
{ | |
instance = (T) FindObjectOfType(typeof(T)); | |
if (instance == null) | |
{ | |
Debug.LogError("An instance of " + typeof(T) + | |
" is needed in the scene, but there is none."); | |
} | |
} | |
return instance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment