Shoot is function
This commit is contained in:
@@ -9,8 +9,6 @@ public class PlayerManager : MonoBehaviour
|
||||
public float runSpeed = 25;
|
||||
public float rotateSpeed = 5;
|
||||
public float mouseSensitive = 200;
|
||||
public float fireRate = 1;
|
||||
private float fireTime;
|
||||
public float buildRate = 0.5f;
|
||||
private float buildTime;
|
||||
private bool run = false;
|
||||
@@ -25,7 +23,6 @@ public class PlayerManager : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
fireTime = fireRate;
|
||||
buildTime = buildRate;
|
||||
playerCamera = GetComponentInChildren<Camera>();
|
||||
rigidBody = GetComponent<Rigidbody>();
|
||||
@@ -41,7 +38,6 @@ public class PlayerManager : MonoBehaviour
|
||||
SelectWeapon();
|
||||
BuildBlock();
|
||||
BuildBarricade();
|
||||
Attack();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
@@ -60,7 +56,6 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
void Rotate()
|
||||
{
|
||||
Debug.Log(playerCamera.transform.localEulerAngles);
|
||||
transform.Rotate(new Vector3(0, rotateSpeed * Input.GetAxis("Mouse X") * mouseSensitive * Time.deltaTime, 0));
|
||||
if (
|
||||
((playerCamera.transform.localEulerAngles.x >= 270 && playerCamera.transform.localEulerAngles.x <= 360) &&
|
||||
@@ -165,16 +160,6 @@ public class PlayerManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void Attack()
|
||||
{
|
||||
WeaponManager weaponManager = weaponList[selectedWeapon].GetComponent<WeaponManager>();
|
||||
if (weaponManager != null && Input.GetMouseButtonDown(0) && fireTime < Time.time)
|
||||
{
|
||||
weaponManager.Attack();
|
||||
fireTime = fireRate * Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
void BuildBarricade()
|
||||
{
|
||||
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);
|
||||
|
@@ -7,41 +7,41 @@ public class WeaponManager : MonoBehaviour
|
||||
public enum WeaponType { None, Shoot, Meele };
|
||||
public WeaponType weaponType = WeaponType.None;
|
||||
public float weaponRange = 1;
|
||||
public ParticleSystem particleShoot;
|
||||
public GameObject spawnShoot;
|
||||
public GameObject particleShoot;
|
||||
public float damage = 0;
|
||||
public float fireRate = 0.5f;
|
||||
private float fireTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
fireTime = fireRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
WeaponAttack();
|
||||
}
|
||||
|
||||
public void Attack()
|
||||
public void WeaponAttack()
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, weaponRange))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (weaponType == WeaponType.Shoot)
|
||||
{
|
||||
if (particleShoot != null && !particleShoot.isPlaying)
|
||||
if (Input.GetMouseButtonDown(0) && fireTime <= Time.time) {
|
||||
if (weaponType == WeaponType.Shoot)
|
||||
{
|
||||
particleShoot.Stop();
|
||||
particleShoot.Play();
|
||||
if (particleShoot != null)
|
||||
{
|
||||
Debug.Log(transform.position);
|
||||
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
|
||||
Destroy(shoot, 0.3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (weaponType == WeaponType.Meele)
|
||||
{
|
||||
else if (weaponType == WeaponType.Meele)
|
||||
{
|
||||
|
||||
}
|
||||
fireTime = fireRate + Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user