Help to fix image position on screen in play mode on mouse click.
Struggle and help from youtube videos i have successfully implemented Screen points to canvas coordinates. on mouse click anywhere on screen in-game mode, i see the image appearing. now i am struggling to permanently fix/position that image on the screen. it disappears when i click the mouse again.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ScrrenToCanavas : MonoBehaviour { public RectTransform m_Parent; public Camera m_camera; public RectTransform m_image; public Canvas m_canvas;
private void Start()
{
Vector2 anchoredPos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Parent, new Vector3 (Screen.width,Screen.height, 1.0f), m_canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : m_camera, out anchoredPos);
// m_image.anchoredPosition = anchoredPos;
}
private void Update()
{
if(Input.GetMouseButtonDown(0))
{
Vector2 anchoredPos;
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Parent, Input.mousePosition, m_canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : m_camera, out anchoredPos);
m_image.anchoredPosition = anchoredPos;
}
}
} alt text
Your answer
Follow this Question
Related Questions
Reset Raw UI Image For Audio Spectrum Data 0 Answers
How to make an event when 2 UI Image touching ? 1 Answer
Weird behaviour dragging a UI Image 0 Answers
find an especific multitouch wich is on a image in the canvas 0 Answers
Trying to get a child component of an Image (Making a floating healthbar) 1 Answer