hand
_1_7_111
4
返回栏目
1k
0.2k
0.5k
0.1k
0k
0.2k
0k
0.7k
0k
0k
0.4k
0.1k
4k
0.2k
0.1k
2k
0.2k
0.2k
0k
0k
0.5k
0k
0.9k
0.1k
1k
0.9k
2k
1k
2k
0.9k
1k
0k
1k
0k
1k
1k
1k
1k
0k
1k
1k
1k
0k
3k
1k
0k
0.3k
1k
0.3k
0.9k
0k
8k
9k
6k
2k
1k
2k
1k
1k
2k
0.6k
1k
0.6k
1k
0.5k
0.2k
2k
2k
2k
1k
2k
0k
0.8k
0.8k
1k
0k
0k
0k
0k
0k
0k
0k
0k
0.3k
0.4k
0.8k
0.3k
5k
1k
3k
7k
6k
3k
3k
1k
0.2k
2k
3k
2k
0.4k
0.5k
3k
2k
7k
3k
4k
2k
1k
6k
6k
1k
1k
0.9k
0.2k
0.3k
0.9k
1k
0k
0.8k
2k
0k
0.4k
0.1k
1k
0.9k
0.2k
1k
1k
0.5k
0k
0k
0.4k
4k
0.4k
2k
3k
1k
1k
1k
3k
5k
0k
1k
2k
0.5k
0k
1k
0k
1k
0.5k
0.8k
返回Unity - 游戏引擎栏目
作者:
贺及楼
成为作者
更新日期:2023-09-17 11:00:19
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttack : MonoBehaviour {
public GameObject arrowPrefab;
private Animator anim;
private Transform leftHandTrans;
private Vector3 shootDir;
private PlayerManager playerMng;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
leftHandTrans = transform.Find("Bip001/Bip001 Pelvis/Bip001 Spine/Bip001 Neck/Bip001 L Clavicle/Bip001 L UpperArm/Bip001 L Forearm/Bip001 L Hand");
}
// Update is called once per frame
void Update () {
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Grounded"))
{
if (Input.GetMouseButtonDown(0))
{
Ray ray= Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
if (isCollider)
{
Vector3 targetPoint = hit.point;
targetPoint.y = transform.position.y;
shootDir = targetPoint - transform.position;
transform.rotation = Quaternion.LookRotation(shootDir);
anim.SetTrigger("Attack");
Invoke("Shoot", 0.1f);
}
}
}
}
public void SetPlayerMng(PlayerManager playerMng)
{
this.playerMng = playerMng;
}
private void Shoot()
{
playerMng.Shoot(arrowPrefab, leftHandTrans.position, Quaternion.LookRotation(shootDir));
}
}
Unity - 游戏引擎
整章节共151节
快分享给你的小伙伴吧 ~