summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSWeapon.cs
blob: 6edcabfa2fb737eadcdb767a0caf4d3d01f86ddb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEngine;
using System.Collections;

namespace Pathfinding.Examples.RTS {
	[HelpURL("https://arongranberg.com/astar/documentation/stable/rtsweapon.html")]
	public class RTSWeapon : MonoBehaviour {
		public bool ranged;
		public float range;
		public float cooldown;
		public float attackDuration;
		public bool canMoveWhileAttacking = false;

		float lastAttackTime = float.NegativeInfinity;

		public virtual bool Aim (RTSUnit target) {
			return Time.time - lastAttackTime >= cooldown;
		}

		public bool isAttacking {
			get {
				return Time.time - lastAttackTime < attackDuration;
			}
		}

		public bool InRangeOf (Vector3 point) {
			return (transform.position - point).sqrMagnitude < range*range;
		}

		public virtual void Attack (RTSUnit target) {
			lastAttackTime = Time.time;
		}
	}
}