using UnityEngine;
using System.Collections;
public class EnemyShooting : MonoBehaviour {
public bool ikOn = false;//IK动画开关
public LineRenderer lineRenderer;
public Light blinkLight;
private Animator ani;
private Transform player;
private PlayerHealth playerHrealth;
public AudioClip shootingClip;//开枪声音
void Awake()
{
ani = GetComponent<Animator> ();
player = GameObject.FindWithTag (GameTags.player).transform;
playerHrealth = player.GetComponent<PlayerHealth> ();
}
void Update()
{
if (ani.GetFloat(HashIDs.shot)>0.5f) {
//计算玩家伤害
playerHrealth.TakeDamage (50);
//开启特效协程
StartCoroutine (ShootEffect ());
}
}
IEnumerator ShootEffect()
{
//开启线性渲染和闪光灯
lineRenderer.enabled = true;
blinkLight.enabled = true;
//设置线性渲染第一个点(枪口位置)
lineRenderer.SetPosition (0, lineRenderer.transform.position);
//设置线性渲染第二个点(玩家上身位置)
lineRenderer.SetPosition (1, player.position + Vector3.up);
//播放开枪声音
AudioSource.PlayClipAtPoint (shootingClip, transform.position);
//等待0.1s
yield return new WaitForSeconds (0.1f);
//关闭线性渲染和闪光灯
lineRenderer.enabled = false;
blinkLight.enabled = false;
}
void OnAnimatorIK(int layerIndex)
{
if (ikOn) {
//权重设置, 右手和眼睛
ani.SetIKPositionWeight (AvatarIKGoal.RightHand, 1);
ani.SetLookAtWeight (1);
//ani.SetIKRotationWeight (AvatarIKGoal.RightHand, 1);
//位置设置
ani.SetIKPosition (AvatarIKGoal.RightHand, player.position+Vector3.up);
ani.SetLookAtPosition (player.position + Vector3.up);
//ani.SetIKRotation (AvatarIKGoal.RightHand, player.rotation);
}
}
}
版权声明:本文为ff_0528原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。