概述
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestDome01Prefab : MonoBehaviour
{
public Animator animator;
public string AnimationClipName;
AnimationClip ST_HY;
private Ray ray;
private RaycastHit raycastHit;
public VideoRawImageScript videoRawImageScript;
// Start is called before the first frame update
void Start()
{
if (animator==null)
{
animator = this.GetComponent<Animator>();
}
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (var item in clips)
{
if (item.name== AnimationClipName)
{
ST_HY = item;
}
}
ClipAddEvent(animator, "ClipEvent", ST_HY.name, ST_HY.length-0.1f);
}
public void ClipEvent()
{
print("视频播放");
videoRawImageScript.MyPause();
}
// Update is called once per frame
void Update()
{
float MouseXXx = Input.GetAxis("Mouse X");
if (Input.GetMouseButton(0))
{
this.transform.Rotate(0, MouseXXx * -10,0);
}
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
Physics.Raycast(ray,out raycastHit);
if (raycastHit.collider.tag=="ST")
{
animator.SetTrigger("ST");
}else if (raycastHit.collider.tag == "TB")
{
animator.SetTrigger("TB");
}
else
{
print("点到空");
}
}
}
/// <summary>
/// 添加动画事件
/// </summary>
/// <param name="animator"></param>
/// <param name="EName"></param>
/// <param name="Cname"></param>
/// <param name="inserTime"></param>
public void ClipAddEvent(Animator animator01,string EName,string Cname,float inserTime)
{
AnimationClip[] clips = animator01.runtimeAnimatorController.animationClips;
for (int i = 0; i < clips.Length; i++)
{
if (clips[i].name==Cname)
{
AnimationEvent event01 = new AnimationEvent();
event01.functionName = EName;
event01.time = inserTime;
clips[i].AddEvent(event01);
break;//出去了
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class VideoRawImageScript : MonoBehaviour
{
public VideoPlayer videoPlayer01;
// Start is called before the first frame update
void Start()
{
if (videoPlayer01==null)
{
videoPlayer01 = this.GetComponent<VideoPlayer>();
}
}
// Update is called once per frame
void Update()
{
if (videoPlayer01.frame ==videoPlayer01.frameCount-0.1f)
{
MyDsetroy();
}
}
public void MyPause()
{
videoPlayer01.Play();
videoPlayer01.frame = (long)0.1f;
this.gameObject.SetActive(true);
}
public void MyDsetroy()
{
videoPlayer01.Stop();
videoPlayer01.frame = (long)0.1f;
this.gameObject.SetActive(false);
}
private void OnDestroy()
{
MyDsetroy();
}
}
最后
以上就是跳跃哈密瓜为你收集整理的Unity鼠标控制旋转,添加动画事件,的全部内容,希望文章能够帮你解决Unity鼠标控制旋转,添加动画事件,所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复