如何用unity画墙,以及如何使用鼠标控制墙在Y轴上的伸缩

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

public class BuildWall : Interactable {
GameObject Cube;//点击到的物体
public Transform ParentCube;//所有生成的物体的父级
GameObject[] SonCube;//子物体
public GameObject WAll;//实例化的模型

private float Speed = 5.0f;
Vector3 Lateposition;
Vector3 nowposition;
float y;

// Use this for initialization
void Start()
{
//SonCube = new GameObject[] { };
}
void Update()
{
if (Input.GetMouseButtonDown(0))//如何实例化一个Cube
{
GameObject wall = Instantiate(WAll , new Vector3(transform.position.x-5.0f, transform.position.y + 0.5f, transform.position.z), transform.rotation);
wall.transform.SetParent(ParentCube);
}
if (Input.GetMouseButton(1))//当鼠标按下右键的时候,如果点击到物体,那么改变点击到的该物体在Y轴上的值
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)&&hit.transform.name!="Plane")
{
y = Input.GetAxis("Mouse Y");
hit.collider.transform.localScale += new Vector3(0, y, 0);
Debug.Log("this is not null");
}
else
{
Debug.Log("this is null");//如果没有碰撞到物体的时候,鼠标改变所有Cube的Y轴的值
SonCube = GameObject.FindGameObjectsWithTag("ParentCube");
y = Input.GetAxis("Mouse Y");
for (int i = 0; i {
SonCube[i].transform.localScale += new Vector3(0, y, 0);
}
}
}
}

你可能感兴趣的:(一百天系列之unity3d)