У меня есть пример кода, где он создает динамические стены для щелчков мышью.Как сделать динамическую модель в единстве 3D?
using UnityEngine;
using System.Collections;
public class CreateWalls : MonoBehaviour {
bool creating;
public GameObject start;
public GameObject end;
public GameObject wallPrehab;
GameObject wall;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
getinput();
}
/*
*this is the method for getting mouse click inputs
*/
void getinput(){
if (Input.GetMouseButtonDown (0)) {
setStart();
} else if (Input.GetMouseButtonUp (0)) {
setEnd();
} else {
if(creating){
adjust();
}
}
}
/*
* getting the mouse clicked position coordinate
*/
void setStart(){
creating = true;
start.transform.position = getWorldPoint();
Debug.Log("Start = " + start.transform.position);
wall = (GameObject) Instantiate (wallPrehab, start.transform.position, Quaternion.identity);
}
/*
* getting the mouse click over position coordinate
*/
void setEnd(){
creating = false;
end.transform.position = getWorldPoint();
Debug.Log("End = " + end.transform.position);
}
/*
* invoking the wall building method
*/
void adjust(){
end.transform.position = getWorldPoint();
adjustWall();
}
/*
* build the wall in between start point and the end point
*/
void adjustWall(){
start.transform.LookAt (end.transform.position);
end.transform.LookAt (start.transform.position);
float distance = Vector3.Distance (start.transform.position, end.transform.position);
wall.transform.position = start.transform.position + distance/2 * start.transform.forward;
wall.transform.rotation = start.transform.rotation;
wall.transform.localScale = new Vector3 (wall.transform.localScale.x, wall.transform.localScale.y, distance);
}
/*
* method where the coordinate we taken from mouse click
*/
Vector3 getWorldPoint(){
Ray ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
return hit.point;
}
return Vector3.zero;
}
}
У меня есть некоторые координаты, каждый из которых находится внизу изображения.
a=(55, 297)
b=(300, 297)
c=(55, 297)
d=(55, 52)
Above coordinates are for this image
теперь я хочу, чтобы построить стены для этих координат. как коробка. Я не знаю, как их поставить (координаты). в основном координаты каждой стены будут (x, y) и b (x, y). другой будет b (x, y) и c (x, y). может кто-нибудь мне помочь в этом Я буду отличным
Вы хотите сделать свой собственный сетки или работать с Unity примитивов? – joreldraw
https://www.youtube.com/watch?v=h5EiXBJ2Zvc что-то вроде этого. надеюсь, что вы получите эту идею. они используют щелчок мыши. но мне нужно, чтобы он работал для скоординированных действий. –