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();
}
}
}
}
}
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
- TriggerManage
- 【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
- 黑马入学_学习blog_第十篇
- 一图明白OpenERP财务记账规则
- 购物节来啦!!!!!!!!!!!
- 趁热打铁之---VS2010基于VFW的视频控件编写,实现预览、拍照功能
- TriggerManage
- Matlab中plot函数及图形修饰说明
- 11g新特性_索引的可见与不可见
- reviewboard搭建环境安装(1):虚拟机vmwork 下安装ubuntu
- Android软键盘弹出时把布局控件顶上去的解决方法
- Java中泛型(1)——泛型介绍(传智播客毕老师视频讲解)
- 解密腾讯SNG云运维平台“织云”
- 程序员应该常去的一些网站
- 最简单也最难——如何获取到Android控件的高度