-
Notifications
You must be signed in to change notification settings - Fork 0
/
FollowChar.cs
39 lines (34 loc) · 1.28 KB
/
FollowChar.cs
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
using UnityEngine;
using System.Collections;
public class FollowChar : MonoBehaviour {
//this class is really shit, if I intend to use the chase cam I should redo the whole thing.
private GameObject Conv;
private Vector3 Target;
public float MincX, MincY, MaxcX, MaxcY, MinX, MinY, MaxX, MaxY;
// Use this for initialization
void Start ()
{
Conv = GameObject.FindGameObjectWithTag("Contravert");
}
// Update is called once per frame
void Update ()
{
if (Conv.transform.position.x > MincX && Conv.transform.position.y > MincY && Conv.transform.position.x < MaxcX && Conv.transform.position.y < MaxcY)
{
Target.z = -10;
if (Conv.transform.position.x < MinX)
Target.x = MinX;
else if (Conv.transform.position.x > MaxX)
Target.x = MaxX;
else
Target.x = Conv.transform.position.x;
if (Conv.transform.position.y < MinY)
Target.y = MinY;
else if (Conv.transform.position.y > MaxY)
Target.y = MaxY;
else
Target.y = Conv.transform.position.y;
transform.position = Vector3.MoveTowards(transform.position, Target, 1);
}
}
}