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

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

2015-03-10 08:43 1146 查看

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 initialization
void 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);
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐