1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-22 17:34:18 +00:00
keep-everything-alive/Assets/Scripts/Generic/StretchToFollow.cs

31 lines
907 B
C#
Raw Normal View History

2020-04-20 16:16:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum StretchToFollowOptions {
HORIZONTAL,
VERTICAL
}
public class StretchToFollow : MonoBehaviour
{
public GameObject target;
public StretchToFollowOptions mode;
private Vector3 startingTargetPosition;
void Start() {
startingTargetPosition = target.transform.position;
transform.position = startingTargetPosition;
}
void Update() {
if(mode == StretchToFollowOptions.HORIZONTAL) {
transform.localScale = new Vector3(Mathf.Abs(target.transform.position.x - startingTargetPosition.x) * 2, transform.localScale.y, transform.localScale.z);
}
else {
transform.localScale = new Vector3(transform.localScale.x, Mathf.Abs(target.transform.position.y - startingTargetPosition.y) * 2, transform.localScale.z);
}
}
}