LET'S MAKE FUN, NOT WAR
0
Noname99

Полу стены(код)

Recommended Posts

Полу стены как в расте: 

using UnityEngine;

 

public class BuildManager : MonoBehaviour

{

    public GameObject halfWallPrefab; // Префаб полустены

    private bool isBuildingHalfWall = false; // Флаг для определения, строится ли полустена в данный момент

 

    void Update()

    {

        if (Input.GetMouseButtonDown(0)) // При нажатии левой кнопки мыши

        {

            if (isBuildingHalfWall)

            {

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                RaycastHit hit;

 

                if (Physics.Raycast(ray, out hit))

                {

                    // Получаем позицию, на которой был произведен клик

                    Vector3 buildPosition = hit.point;

 

                    // Строим полустену

                    BuildHalfWall(buildPosition);

                }

            }

        }

    }

 

    void BuildHalfWall(Vector3 position)

    {

        // Создаем полустену на заданной позиции

        Instantiate(halfWallPrefab, position, Quaternion.identity);

    }

 

    public void ToggleBuildMode()

    {

        // Переключаем режим строительства полустены

        isBuildingHa

lfWall = !isBuildingHalfWall;

    }

}

Edited by Noname99

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
0