纳金网
标题:
编辑器自动生成Cube墙 - 小球打墙
[打印本页]
作者:
烟雨
时间:
2015-5-30 02:50
标题:
编辑器自动生成Cube墙 - 小球打墙
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MyWallBall : EditorWindow
{
public int row;
public int line;
public GameObject cube;
public GameObject plane;
public GameObject sqhere;
public float Spead = 5;
[MenuItem("My Editor/My WallBall")]
static void Init()
{
EditorWindow.GetWindow(typeof(MyWallBall));
}
void OnGUI()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Line");
line = EditorGUILayout.IntField(line);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Row");
row = EditorGUILayout.IntField(row);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Object");
cube = EditorGUILayout.ObjectField(cube, typeof(GameObject)) as GameObject;
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("Create Wall"))
{
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.position += new Vector3(0, -0.5f, 0);
plane.transform.localScale += new Vector3(10, 0, 10);
cube.AddComponent<Rigidbody>();
for (int i = 0; i < line; i++)
{
for (int j = 0; j < row; j++)
{
if (i == 0 && j == 0)
{
continue;
}
float r = Random.Range(0f, 1f);
float g = Random.Range(0f, 1f);
float b = Random.Range(0f, 1f);
Color color=new Color(r,g,b);
GameObject cub = Instantiate(cube, new Vector3(j, i, 0), Quaternion.identity) as GameObject;
cub.gameObject.renderer.material.color = color;
}
}
}
if (GUILayout.Button("shoot"))
{
sqhere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sqhere.transform.localScale -= new Vector3(0.5f, 0.5f, 0.5f);
sqhere.transform.position -= new Vector3(0, 50, 0);
sqhere.AddComponent<Rigidbody>();
}
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 pos = ray.GetPoint(100f);
if (Input.GetMouseButtonDown(0))
{
GameObject rg = Instantiate(sqhere, ray.origin, Quaternion.identity) as GameObject;
rg.rigidbody.AddForce(pos.normalized * 2000f);
Destroy(rg.gameObject, 2f);
}
}
}
复制代码
作者:
fanios
时间:
2016-12-15 18:10
棒!我也在做打墙游戏
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5