public class ParentUsing : MonoBehaviour
{
public static bool UIVision;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void ParentSet(GameObject newParentCursor)
{
gameObject.transform.parent = newParentCursor.transform;
}
public void OnTriggerEnter(Collider newParentCursor)
{
if(newParentCursor.tag == "Cursor")
{
UIVision = true;
if (Input.GetKeyDown(KeyCode.E))
{
ParentSet(newParentCursor);
}
}
}
}
using UnityEngine;
public class ParentUsing : MonoBehaviour
{
GameObject _targetGO;
bool UIVision;
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && _targetGO != null)
{
ParentSet(_targetGO);
}
}
void ParentSet(GameObject newParentCursor)
{
gameObject.transform.parent = newParentCursor.transform;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Cursor")
{
UIVision = true;
_targetGO= other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
if(_targetGO==other.gameObject)_targetGO = null;
}
}