纳金网

标题: 右键任意位置显示菜单 [打印本页]

作者: star-小虎    时间: 2013-10-11 17:26
标题: 右键任意位置显示菜单
以后很简单的在任意位置显示右键菜单。
当然了,你显示其他东西也可以;
创建ContextMenu.cs脚本,然后给任意对象:
[url=]复制代码[/url]
[backcolor=rgb(250, 250, 250) !important][size=1em]1

[size=1em]2

[backcolor=rgb(250, 250, 250) !important][size=1em]3

[size=1em]4

[backcolor=rgb(250, 250, 250) !important][size=1em]5

[size=1em]6

[backcolor=rgb(250, 250, 250) !important][size=1em]7

[size=1em]8

[backcolor=rgb(250, 250, 250) !important][size=1em]9

[size=1em]10

[backcolor=rgb(250, 250, 250) !important][size=1em]11

[size=1em]12

[backcolor=rgb(250, 250, 250) !important][size=1em]13

[size=1em]14

[size=1em][backcolor=rgb(250, 250, 250) !important][size=1em]using UnityEngine;
[size=1em]using System.Collections;
[backcolor=rgb(250, 250, 250) !important][size=1em]   
[size=1em]public class ContextMenu : MonoBehaviour {
[backcolor=rgb(250, 250, 250) !important][size=1em]   
[size=1em]void OnGUI(){  
[backcolor=rgb(250, 250, 250) !important][size=1em]    if(Input.GetMouseButton(1))
[size=1em]    {  
[backcolor=rgb(250, 250, 250) !important][size=1em]        GUILayout.BeginArea (new Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y,200,200));
[size=1em]        GUILayout.Box("This is a Context Menu");
[backcolor=rgb(250, 250, 250) !important][size=1em]        GUILayout.EndArea ();
[size=1em]        }      
[backcolor=rgb(250, 250, 250) !important][size=1em]    }
[size=1em]}





作者: nts    时间: 2013-10-13 11:18
请问是在编辑模式下吗




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5