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; // <20>ӵ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
|||
|
public GameObject firePrefab;
|
|||
|
public Transform[] bulletSpawn; // <20>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
public float bulletVelocity = 30f; // <20>ӵ<EFBFBD><D3B5>ٶ<EFBFBD>
|
|||
|
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|||
|
RaycastHit hitInfo;
|
|||
|
|
|||
|
if (Input.GetMouseButtonDown(0))
|
|||
|
{
|
|||
|
if (Physics.Raycast(ray, out hitInfo))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
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);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|