Build System
下载完毕,导入。
下面这个脚本,直接挂载到一个空物体,新建一个 3D物体 立方体,将其设置为 BuildGameObject变量的值(如下图所示)。新建一个 按钮button,来触发placeBool函数即可 实现放置基本的物体。
using UnityEngine;
using BuildSystem;
public class BuildManage : MonoBehaviour {
public Material ghostMaterial;//放置物体 时候的 材质
private Material goMaterial;
//**********************************************************************************************
[Header("Input Settings")]
[Tooltip("Key to press to enable the builder mode. This is also used by ObjectSelector")]
public KeyCode toggleKey = KeyCode.E;
[Tooltip("Key to press to place a item in the scene")]
public KeyCode placeKey = KeyCode.Mouse0;
[Tooltip("Key to press rotate (forward) the object based on snapRotaionDeg")]
public KeyCode positiveRotateKey = KeyCode.Mouse1;
[Tooltip("Key to press rotate (backward) the object based on snapRotaionDeg")]
public KeyCode negativeRotateKey = KeyCode.None;
[Header("More Settings")]
[Tooltip("Disable the remover script when placer is active. Note: remover must be next to this script")]
public bool shouldToggleRemover = true;
[Tooltip("Max distance from camera where you can place objects")]
public float maxPlaceDistance = 100f;
/****************************************************
* Editor Interface
* *************************************************/
[Tooltip("Camera used to raycast and find place position, if empty the script will try to use the main camera")]
public Camera cam;
public LayerMask movementMask;//设置 LayerMask
public GameObject buildGameObject;//建设的物体
/****************************************************
* Variables
* *************************************************/
bool isActive = true;
bool canPlace = false;
bool mouseIsNotOnUI = true;
//object rotation
float objectSnapCurrentRotaion = 0;
//object pivot
bool usingFakePivot = false;
/****************************************************
* Events
* *************************************************/
public delegate void BuildEvent();
public event BuildEvent OnGhostObjectCreation;
public event BuildEvent OnGhostObjectDestroy;
public event BuildEvent OnGhostObjectPlace;
/****************************************************
* Components & references
&