finally get pathfinding done?
This commit is contained in:
parent
7b151c1a53
commit
7bd61df481
23 changed files with 1408 additions and 785 deletions
53
Assets/Scripts/RangedWeapon.cs
Normal file
53
Assets/Scripts/RangedWeapon.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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)
|
||||
{
|
||||
fired = true;
|
||||
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);
|
||||
isAiming = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateProjectile(Vector3 target)
|
||||
{
|
||||
Projectile newProjectile = Instantiate(projectile, transform.position, Quaternion.identity);
|
||||
newProjectile.RotateToTarget(target);
|
||||
newProjectile.tag = tag;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue