You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
using UnityEngine;
|
|
//http://answers.unity.com/answers/1778449/view.html
|
|
public class Glider : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// The speed when falling
|
|
/// </summary>
|
|
[SerializeField]
|
|
private float m_FallSpeed = 0f;
|
|
|
|
private Animator animator;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private Rigidbody2D m_Rigidbody2D = null;
|
|
public bool IsGliding = false;
|
|
|
|
// Awake is called before Start function
|
|
void Awake()
|
|
{
|
|
m_Rigidbody2D = GetComponent<Rigidbody2D>();
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (IsGliding && m_Rigidbody2D.velocity.y < 0f && Mathf.Abs(m_Rigidbody2D.velocity.y) > m_FallSpeed)
|
|
{
|
|
m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, Mathf.Sign(m_Rigidbody2D.velocity.y) * m_FallSpeed);
|
|
animator.SetBool("isGliding", true);
|
|
}
|
|
else
|
|
{
|
|
animator.SetBool("isGliding", false);
|
|
}
|
|
}
|
|
|
|
public void StartGliding()
|
|
{
|
|
IsGliding = true;
|
|
}
|
|
|
|
public void StopGliding()
|
|
{
|
|
IsGliding = false;
|
|
}
|
|
|
|
public void ToggleGliding()
|
|
{
|
|
IsGliding = !IsGliding;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flag to check if gliding
|
|
/// </summary>
|
|
///
|
|
//public bool IsGliding { get; set; } = false;
|
|
|
|
} |