- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
- 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);
- }
- }
- }
复制代码 |
|