您的位置:首页 > 移动开发 > Unity3D

[Unity3d]脚本相互调用以及控制

2013-11-08 17:54 369 查看
在unity中,我们时常碰到要调用另外一个脚本中的方法,或者通过代码来控制该脚本是否启动执行,下面就贴上这段脚本。

using UnityEngine; using System.Collections;  public class scriptChange : MonoBehaviour {     int i = 0; 	// Use this for initialization 	void Start () { 	 	} 	 	// Update is called once per frame 	void Update () {         //鼠标右击         if (Input.GetMouseButtonDown(1)) 	    {             print("mousedown");             MouseLook obj = (MouseLook)gameObject.GetComponent("MouseLook");             //C#调用另外一个脚本的方法             //if (obj == null)             //{             //    print("null");             //}             ////print(obj);             //else             //{             //    print("OK");             //    print(obj);             //    obj.active = true;             //    obj.test();             //}              //鼠标右击开始和关闭             if (i == 0)             {                 //开启脚本                 transform.GetComponent<MouseLook>().enabled = true;             }             else             {                 transform.GetComponent<MouseLook>().enabled = false;             }             i++;             i = i % 2; 	    } 	     	} }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: