- 博客(12)
- 收藏
- 关注
原创 按钮点击事件注册
一、using UnityEngine;using System.Collections;using UnityEngine.UI;using UnityEngine.Events;public class ClickObject : MonoBehaviour{ void Start () { //获取按钮游戏对象 GameObject btnObj = GameObject.Find ("Canvas/Button"); //
2020-12-08 10:35:01
873
原创 Unity3D UI多元素布局
1.Grid Layout Group组件实现布局1.新建空物体1,添加Grid Layout Group组件作为布局区域,把需要布局的对象作为布局区域的子物体。2.新建空物体2,作为需要布局的对象,此空物体会作为布局的元素,修改Cell Size时会改变此空物体的宽和高,所以需要此空物体作为其他需要布局的对象父物体,这样在修改布局宽高的时候不会改变布局对象的宽高修改Cell Size可以修改每个元素(一级子物体)在布局区域内所占的宽和高。2.Toggle Group组件1.给Imag
2020-12-04 11:07:14
426
原创 UI控件检测鼠标悬停
UI控件检测鼠标悬停 if (Input.GetMouseButtonUp(1))//右键 { RectTransform rctTr = _TreeView.gameObject.GetComponent<RectTransform>(); //如果Canvas为Overlay不需要传Camera参数,否则需要传Camera //Canvas canvas = GetComponent<
2020-12-04 11:06:30
175
原创 Unity相机视野控制与相机旋转
射线检测物体并拖拽物体using UnityEngine;public class RaycastTest : MonoBehaviour{ private bool isRay=true; Vector3 offset; Vector3 screenTarget; GameObject targetGameObject;//射线碰撞的物体 RaycastHit hit; public LayerMask clickableLayer;//屏幕射线可碰.
2020-07-01 14:42:08
549
原创 TCP通信基于Unity3D的聊天室/UDP通信
客户端using System.Text;using System.Net.Sockets;using System.Net;using UnityEngine;using UnityEngine.UI;using System.Threading;public class _GameManager : MonoBehaviour{ public string ipAdress = "10.10.6.59"; public int port = 7788; publ
2020-07-01 14:41:20
325
原创 C#笔记
1.数组定义1.int[] array = {1,2,3,4}//声明时赋值2.int[] array = new int[10]3.int[] array = new int[4]{1,2,3,4}//指定长度并赋值2.try{ } catch{ }程序异常处理使程序更健壮using System;namespace Test{ class Program { static void Main(string[] args) {
2020-06-28 09:56:05
248
转载 Unity Space.Word&self与Translate移动
float Speed; public bool isWorldSpace; void Start() { Speed = 20.0f; //transform.Rotate(60, 0, 60);//旋转 } void Update() { //Rotate or Move the GameObject in World Space if in the isWorldSpace state .
2020-06-28 09:55:07
3827
1
原创 Canvas下GameObject的位置坐标
轴心点是计算位置坐标的点,Rec Transform面板上的位置信息表示的是轴心点与其锚点的位置关系,当物体旋转时,绕轴心点旋转
2020-06-28 09:20:42
285
原创 3DTank大战总结
1.transform.Find()的用法transform.Find 只能找到所在物体的子物体Debug.Log(transform.Find(“test”)); 结果是null空值。想要查找子辈的子辈怎么,需要指定全路径Debug.Log(transform.Find(“GameObject (3)/test”));即可找到。2.实例化物体,并控制物体移动Instantiate(物体,位置,方向)if(Input.GetKeyDown(fireKey)){GameObject
2020-06-20 21:23:24
402
原创 Unity3D组件获取
1.获取游戏物体自身组件1.transform组件是内置的组件,直接通过transform访问。2.[组件类型] [变量]=GetComponet<组件类型>();Rigidbody rig=GetComponet();Collider[] colliders=GetComponets();//多个碰撞器3.Script script=GetComponets...
2020-06-20 21:22:41
1756
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人