- meshRenderer渲染顺序
GetComponent<MeshRenderer>().sortingOrder = GetComponent<SpriteRenderer>().sortingOrder + 1;
- 如果正在调用
if (IsInvoking("jiu"))
{
CancelInvoke("jiu");
}
- Renderer渲染顺序
piece.GetComponent<Renderer>().material.renderQueue = this.GetDrawPriorityPiece(n);
- 左键
eventData.button==PointerEventData.InputButton.Left
- 屏幕点在矩形内的世界坐标
RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").GetComponent<RectTransform>(), Input.mousePosition, null, out position);
- NavMeshAgent组件相关
if (agent.enabled)
{
if (agent.remainingDistance < minDistance)
{
agent.Stop();
agent.enabled = false;
}
}
if (Input.GetMouseButtonDown(0))
{
SetDestination(target.position);
}
anim.SetFloat("speed", agent.velocity.magnitude);
- 层标记计算方法,如果还想碰撞继续加等于
hitMask += 1 << LayerMask.NameToLayer("Entrance")
- 游戏截图
ScreenCapture.CaptureScreenshot("游戏截图");
- 加载图片
public static IEnumerator LoadImage(string url, Image image)
{
WWW www = new WWW(url);
while (!www.isDone)
yield return www;
Texture2D texture = www.texture;
Sprite sp = Sprite.Create(
texture,
new Rect(0, 0, texture.width, texture.height),
new Vector2(0.5f, 0.5f));
image.sprite = sp;
}
- 滑动到哪里了
public void OnEndDrag(PointerEventData eventData)
{
scrollRect.normalizedPosition
}
- 2D射线
Physics2D.Linecast();
- 滑轮向下
Input.GetAxis("Mouse ScrollWheel") < 0
- 判断点击是不是UI
EventSystem.current.IsPointerOverGameObject() == false
- 动画信息
private void ChangedATKSpeed()
{
if (m_anmator != null)
{
AnimatorStateInfo asi = m_animator.GetCurrentAnimatorStateInfo(0);
if (asi.IsName("attack"))
{
m_animator.speed = 3 / m_attackSpeed;
}
}
}
- 加载设置材质
Texture tex = Resources.Load("dog", typeof(Texture)) as Texture;
Debug.Log(tex);
mr.material.SetTexture("_Maintext", tex);
- scrollRect相关
scrollRect.horizontalNormalizedPosition = pageArray[index];
- 相对力AddRelativeForce()
- 编辑器在运行吗
UnityEditor.EditorApplication.isPlaying
- AddComponentMenu属性允许您将脚本放在“Component”菜单中的任何位置,而不仅仅是“Component-> Scripts”菜单
[AddComponentMenu("UI/UIButton")]