降落伞
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// 降落伞实例
public GameObject paraObj = null;
// 物体减速距离
public float dragDis = 4f;
// 是否打开降落伞
bool deployed = false;
void Update () {
// new Ray实例
Ray testRay = new Ray (transform.position, Vector3.down);
// out 结构体
RaycastHit infomation;
if (!deployed) {
if( Physics.Raycast( testRay, out infomation, dragDis ) )
{
if( infomation.collider.tag == "碰撞对象的tag")
{
deployed = true;
// 设置物体阻力
GetComponent<Rigidbody>().drag = 4f;
Debug.Log(" 打开降落伞 ");
paraObj.Animation.Play("打开降落伞动画");
}
}
}
}
void OnCollisionEnter()
{
paraObj.Animation.Play("关闭降落伞动画");
Debug.Log (" 关闭降落伞 ");
}
}