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

public class FollowPlayer : MonoBehaviour
{
	public enum Target
	{
		Self,
		Other
	}

	public Target target;

	public bool inheritScale = true;

	private Vector3 startScale;

	private Player ownPlayer;

	private void Start()
	{
		startScale = base.transform.localScale;
		ownPlayer = GetComponentInParent<Player>();
		if (!ownPlayer)
		{
			ownPlayer = GetComponentInParent<SpawnedAttack>().spawner;
		}
	}

	private void LateUpdate()
	{
		Player player = null;
		player = ((target != Target.Other) ? ownPlayer : PlayerManager.instance.GetOtherPlayer(ownPlayer));
		if (inheritScale)
		{
			base.transform.localScale = new Vector3(player.transform.localScale.x * startScale.x, player.transform.localScale.y * startScale.y, player.transform.localScale.z * startScale.z);
		}
		base.transform.position = player.transform.position;
		base.transform.rotation = player.transform.rotation;
	}
}