summaryrefslogtreecommitdiff
path: root/GameCode/TracerRound.cs
blob: 201a5f7339b02d7df961af038634dbcf732444c0 (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
using UnityEngine;

public class TracerRound : MonoBehaviour
{
	public GameObject bullet;

	public GameObject bulletSpawnPos;

	private TracerTarget target;

	private MoveTransform move;

	private bool done;

	private void Start()
	{
		move = GetComponent<MoveTransform>();
		bullet = Object.Instantiate(bullet, bulletSpawnPos.transform.position, bulletSpawnPos.transform.rotation);
		bullet.GetComponent<ProjectileHit>().damage *= base.transform.localScale.x;
		GetComponentInParent<SpawnedAttack>().CopySpawnedAttackTo(bullet);
		target = bullet.GetComponent<TracerTarget>();
		GetComponentInParent<ProjectileHit>().AddHitActionWithData(Hit);
		bullet.GetComponentInParent<ProjectileHit>().AddHitActionWithData(Hit);
	}

	public void Hit(HitInfo hit)
	{
		if ((bool)hit.transform.root.GetComponent<Player>())
		{
			base.transform.SetParent(null);
			base.gameObject.AddComponent<RemoveAfterSeconds>().seconds = 10f;
			base.gameObject.AddComponent<FollowTransform>().target = hit.transform;
		}
	}

	private void Update()
	{
		if (target != null)
		{
			target.SetPos(base.transform.position, Vector3.Cross(Vector3.forward, base.transform.forward), move);
		}
		if (bullet == null && !done)
		{
			done = true;
			GetComponentInChildren<ParticleSystem>().Stop();
		}
	}
}