51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
public class Shoot : MonoBehaviour
|
|
{
|
|
public GameObject bulletPrefab; // 子弹预制体
|
|
public GameObject firePrefab;
|
|
public Transform[] bulletSpawn; // 子弹生成位置
|
|
public float bulletVelocity = 30f; // 子弹速度
|
|
|
|
|
|
void Update()
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hitInfo;
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
if (Physics.Raycast(ray, out hitInfo))
|
|
{
|
|
//射线选择人物
|
|
if (hitInfo.collider.gameObject.name == "enemy")
|
|
{
|
|
FireWeapon(hitInfo.collider.gameObject.transform);
|
|
GoldFirePoint();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void GoldFirePoint()
|
|
{
|
|
GameObject fireobj0 = Instantiate(firePrefab, bulletSpawn[0].position, bulletSpawn[0].rotation);
|
|
GameObject fireobj1 = Instantiate(firePrefab, bulletSpawn[1].position, bulletSpawn[1].rotation);
|
|
Destroy(fireobj0, 0.5f);
|
|
Destroy(fireobj1,0.5f);
|
|
}
|
|
private void FireWeapon(Transform transform)
|
|
{
|
|
|
|
GameObject bullet = Instantiate(bulletPrefab, bulletSpawn[0].position, bulletSpawn[0].rotation);
|
|
bullet.transform.DOMove(transform.position,0.5f);
|
|
|
|
GameObject bullet1 = Instantiate(bulletPrefab, bulletSpawn[1].position, bulletSpawn[1].rotation);
|
|
bullet1.transform.DOMove(transform.position, 0.5f);
|
|
|
|
}
|
|
|
|
|
|
}
|