在hierarchy面板创建一个球体,作为子弹,然后对其进行复制,对于复制体 将其作为Fireposition
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunManager : MonoBehaviour
{
private float maxYRotation = 120;
private float minYRotation = 0;
private float maxXRotation = 60;
private float minXRotation = 0;
private float shootTime = 1;
private float shootTimer=0;
private void Update()
{
shootTime += Time.deltaTime;
if (shootTimer >= shootTime)
{
//可以攻击
}
float xPosPercent = Input.mousePosition.x / Screen.width;
float yPosPercent = Input.mousePosition.y / Screen.height;
float xAngle = -Mathf.Clamp(yPosPercent * maxXRotation, minXRotation,maxXRotation)+15;
float yAngle = Mathf.Clamp(xPosPercent * maxXRotation, minYRotation, maxYRotation) - 60;
transform.eulerAngles = new Vector3(xAngle, yAngle, 0);
}
}