| . | |
| using System; |
| |
| using UnityEngine; |
| |
| |
| |
| public class MeteorSmash : MonoBehaviour |
| |
| { |
| |
| private void Start() |
| |
| { |
| |
| Vector3 vector = Vector3.RotateTowards(Vector3.forward, Vector3.up, 0.017453292f * this.m_spawnAngle, 0f); |
| |
| vector = (Quaternion.Euler(0f, UnityEngine.Random.value * 360f, 0f) * vector).normalized * this.m_spawnDistance; |
| |
| this.m_startPos = base.transform.position + vector; |
| |
| this.m_originalScale = this.m_meteorObject.transform.localScale; |
| |
| this.m_meteorObject.SetActive(true); |
| |
| this.m_landingEffect.SetActive(false); |
| |
| this.m_meteorObject.transform.position = Vector3.Lerp(this.m_startPos, base.transform.position, this.m_speedCurve.Evaluate(0f)); |
| |
| this.m_meteorObject.transform.localScale = Vector3.Lerp(Vector3.zero, this.m_originalScale, this.m_scaleCurve.Evaluate(0f)); |
| |
| this.m_meteorObject.transform.LookAt(base.transform.position); |
| |
| } |
| |
| |
| |
| private void Update() |
| |
| { |
| |
| if (this.m_crashed) |
| |
| { |
| |
| return; |
| |
| } |
| |
| this.m_timer += Time.deltaTime; |
| |
| float num = this.m_timer / this.m_timeToLand; |
| |
| this.m_meteorObject.transform.position = Vector3.Lerp(this.m_startPos, base.transform.position, this.m_speedCurve.Evaluate(num)); |
| |
| this.m_meteorObject.transform.localScale = Vector3.Lerp(Vector3.zero, this.m_originalScale, this.m_scaleCurve.Evaluate(num)); |
| |
| if (this.m_timer < this.m_timeToLand && !this.m_crashed) |
| |
| { |
| |
| return; |
| |
| } |
| |
| this.m_crashed = true; |
| |
| this.m_landingEffect.SetActive(true); |
| |
| } |
| |
| |
| |
| [global::Tooltip("Should be a child of this object.")] |
| |
| public GameObject m_meteorObject; |
| |
| |
| |
| [global::Tooltip("Should be a child of this object.")] |
| |
| public GameObject m_landingEffect; |
| |
| |
| |
| [Header("Timing")] |
| |
| public AnimationCurve m_speedCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f); |
| |
| |
| |
| public AnimationCurve m_scaleCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f); |
| |
| |
| |
| public float m_timeToLand = 10f; |
| |
| |
| |
| [Header("Spawn Position")] |
| |
| public float m_spawnDistance = 500f; |
| |
| |
| |
| public float m_spawnAngle = 45f; |
| |
| |
| |
| private float m_timer; |
| |
| |
| |
| private bool m_crashed; |
| |
| |
| |
| private Vector3 m_startPos; |
| |
| |
| |
| private Vector3 m_originalScale; |
| |
| } |
| |
| |