unity 开门-碰撞体与触发器

碰撞体与触发器-开门

打开unity5.2,添加plane,添加资源包,加入第三人称人物,导入有打开动画的门,添加一个球体,作为触发器

/**
 * 
 * 碰撞体与触发器
 * 
 * */
using UnityEngine;
using System.Collections;

public class Demo1 : MonoBehaviour {
    public GameObject obj01;
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }
    /// <summary>
    /// 第三人称人物,触发进入函数
    /// </summary>
    /// <param name="e"></param>
    void OnTriggerEnter(Collider e)
    {
        if (e.name == "Sphere")//进入名为“sphere”的区域,播放动画
        {
            obj01.GetComponent<Animation>().Play("OPendoor1");    
        }
    }
}
原文地址:https://www.cnblogs.com/ShineaSYR/p/5871076.html