Scriptum/Assets/StickToObject.cs

31 lines
564 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StickToObject : MonoBehaviour
{
public GameObject Obj;
private Transform objectTransform;
void Start()
{
objectTransform = Obj.transform;
}
void LateUpdate()
{
Vector3 temp = transform.position;
temp.x = objectTransform.position.x;
temp.y = objectTransform.position.y;
transform.position = temp;
if(Obj.active == false)
{
gameObject.SetActive(false);
}
}
}