TriggerManage

来源:互联网 发布:淘宝网手提包包 编辑:程序博客网 时间:2024/05/21 15:50
using UnityEngine;
using System.Collections;




public class TriggerManage : MonoBehaviour
{


    public Animation animation;
    public AudioSource audioSource;
    public AudioClip audioClip;
    void Start()
    {
    }


    void OnTriggerEnter(Collider hit)
    {
        if (hit.tag == "Player")
        {
            if (gameObject.name == "PlayAnimation")
            {
                animation["AnimationClip"].time = 0;
                animation["AnimationClip"].speed = 1.0f;
                animation.Play("AnimationClip");
            }
            else if (gameObject.name == "PlayMusic")
            {
                if (!audioSource.isPlaying)
                {
                    audioSource.loop = true;
                    audioSource.clip = audioClip;
                    audioSource.playOnAwake = false;
                    audioSource.Play();
                }
            }
        }
    }


    void OnTriggerExit(Collider hit)
    {
        if (hit.tag == "Player")
        {
            if (gameObject.name == "PlayAnimation")
            {
                animation["AnimationClip"].time = animation["AnimationClip"].clip.length;
                animation["AnimationClip"].speed = -1.0f;
                animation.Play("AnimationClip");
            }
            else if (gameObject.name == "PlayMusic")
            {
                if (audioSource.isPlaying)
                {
                    audioSource.Stop();
                }
            }
        }
    }
}
0 0
原创粉丝点击