T
T
TupaDev2021-05-31 19:53:02
Unity
TupaDev, 2021-05-31 19:53:02

How to block movement along Y?

How to block the movement of an object along Y in C#?
In this script -

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovePlayer : MonoBehaviour
{
    public Transform  player;

    public static float speed= 10f;

    void Start()
    {
        speed = 10f;
    }

public float distance = 10f;
 
void OnMouseDrag()
    {
        Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance); // переменной записываються координаты мыши по иксу и игрику
        Vector3 objPosition = Camera.main.ScreenToWorldPoint(mousePosition); // переменной - объекту присваиваеться переменная с координатами мыши
        transform.position = objPosition; // и собственно объекту записываються координаты
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2021-05-31
@TupaDev

objPosition.y = transform.position.y;
transform.position = objPosition;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question