58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class RangedWeapon : Weapon
|
|
{
|
|
private Camera cam;
|
|
private Vector3 mousePos;
|
|
public bool fired;
|
|
public bool isAiming;
|
|
[SerializeField] private Projectile projectile;
|
|
private void Start()
|
|
{
|
|
cam = Camera.main;
|
|
}
|
|
|
|
public override void TryAttack()
|
|
{
|
|
if (!fired)
|
|
{
|
|
AttackEffects();
|
|
}
|
|
}
|
|
|
|
public void Reload()
|
|
{
|
|
fired = false;
|
|
}
|
|
protected override void AttackEffects()
|
|
{
|
|
isAiming = true;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isAiming)
|
|
{
|
|
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
CreateProjectile(mousePos);
|
|
fired = true;
|
|
isAiming = false;
|
|
thisEntity.hasAttacked = true;
|
|
}
|
|
else if (Input.GetMouseButtonDown(1))
|
|
{
|
|
isAiming = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CreateProjectile(Vector3 target)
|
|
{
|
|
Projectile newProjectile = Instantiate(projectile, transform.position, Quaternion.identity);
|
|
newProjectile.RotateToTarget(target);
|
|
newProjectile.tag = tag;
|
|
}
|
|
}
|