Beginner Tutorial How to Write Code in Unity for Sprites

Опубликовано: 28 Октябрь 2024
на канале: paradise _hope
37
0

using UnityEngine;

public class StrikerMovement : MonoBehaviour
{
public bool isDragging = false;
void Start()
{
// Debug.Log("-=========================================================================== " +);


}
void Update()
{
//Debug.Log("-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ " );

if (Input.GetMouseButton(0))//down
{
isDragging = true;
Vector3 mousePos = Input.mousePosition;
Debug.Log("---------------------------------------------"+mousePos);
mousePos.z = Camera.main.nearClipPlane; // Set the z-coordinate to be in front of the camera
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
transform.position = mousePos;
}
else
{
isDragging = false;
}
}
}


/* Camera.main.nearClipPlane
refers to the distance from the camera
at which objects start to be rendered. Anything closer
to the camera than this distance will not be visible. This parameter
is part of the camera's frustum, which is a pyramid-shaped area representing the camera's
field of view. The near clipping plane defines the closest boundary of this frustum.

Setting a proper near clipping plane
distance is crucial for avoiding visual artifacts like clipping or z-fighting, where objects appear to flicker or disappear due to insufficient depth precision. */