unity->C#->组件->点击cube1 可以控制 光源亮度 cube1变大变小 cube2旋转 sphere颜色 cylander走停

来源:互联网 发布:视频后期制作软件ae 编辑:程序博客网 时间:2024/04/29 04:57

1.场景  一个光源, 一个cube1 一个cube2   一个sphere 一个Cylinder
 
点击cube1   可以控制 光源亮度  cube1变大变小  cube2旋转  sphere颜色  cylander走停

using UnityEngine;using System.Collections;public class cude1 : MonoBehaviour {public static  bool aaa=false;void Start () {}void Update () {if (aaa == true) {transform.localScale = new Vector3 (2.0F, 2.0F, 2.0F);//改变缩放比例大小} else {transform.localScale = new Vector3 (1.0F, 1.0F, 1.0F);}}void OnMouseDown(){aaa = !aaa;}}

using UnityEngine;using System.Collections;public class cude2 : MonoBehaviour {//public cude1 c1;public float yRotation = 0.0f;void Start () {}void Update () {if(cude1.aaa){yRotation++;transform.eulerAngles = new Vector3(0, yRotation, 0);//旋转}}}

using UnityEngine;using System.Collections;public class cylinder : MonoBehaviour {// Use this for initializationvoid Start () {}void Update () {if (cude1.aaa) {this.transform.Translate (0.1f, 0, 0, Space.World);//x轴方向移动} else {this.transform.Translate (-0.1f, 0, 0, Space.World);}}}

using UnityEngine;using System.Collections;public class light : MonoBehaviour {public float a=0.0f;void Start () {}void Update () {if (cude1.aaa) {if (a < 8.0f) {a = a + 0.1f;this.gameObject.GetComponent<Light> ().intensity = a;//光照强度修改} else {a = 0.0f;this.gameObject.GetComponent<Light> ().intensity = a;}} }}

using UnityEngine;using System.Collections;public class color : MonoBehaviour {private MeshRenderer mm;void Start () {mm = this.gameObject.GetComponent<MeshRenderer> ();//mm代表材质球}void Update () {if (cude1.aaa) {mm.material.color = new Color (0, 1, 0);} else {mm.material.color = new Color (1, 1, 0);}}}


0 0
原创粉丝点击