summaryrefslogtreecommitdiff
path: root/GameCode/BulletPoint.cs
blob: d7a9157aa1b870964972f4d90a649119a5743d67 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using UnityEngine;

public class BulletPoint : MonoBehaviour
{
	public LayerMask mask;

	private Gun gun;

	private MoveTransform move;

	private ProjectileHit hit;

	private float counter = 5f;

	private void Start()
	{
		gun = GetComponent<Gun>();
		Gun obj = gun;
		obj.ShootPojectileAction = (Action<GameObject>)Delegate.Combine(obj.ShootPojectileAction, new Action<GameObject>(Fire));
	}

	private void Attack()
	{
		gun.Attack(1f, forceAttack: true);
	}

	private void Fire(GameObject projectile)
	{
		move = projectile.GetComponent<MoveTransform>();
	}

	private void Update()
	{
		if ((bool)move)
		{
			counter = 0f;
			Vector3 vector = base.transform.position - base.transform.root.position;
			RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.root.position, vector, vector.magnitude, mask, -10000f);
			Vector3 vector2 = base.transform.position;
			if (raycastHit2D.transform != null)
			{
				vector2 = raycastHit2D.point - (Vector2)vector.normalized * 0.1f;
			}
			move.velocity = Vector2.Lerp(move.velocity, (vector2 - move.transform.position) * 50f, TimeHandler.deltaTime * 50f);
		}
		else
		{
			counter += TimeHandler.deltaTime;
			if (counter > 2f)
			{
				Attack();
			}
		}
	}
}