Follow Mouse

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

using UnityEngine;

public class FollowMouse : MonoBehaviour


{
[SerializeField]
private Canvas ParentCanvas;

private void Update()


{
Vector2 pos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(ParentCanvas.transform as
RectTransform, Input.mousePosition, ParentCanvas.worldCamera, out pos);
transform.position = ParentCanvas.transform.TransformPoint(pos);
}
}

You might also like