单例
using UnityEngine;
using System.Collections;
public class IsRun
{
private static readonly IsRun tf=new IsRun();
private IsRun()
{
}
public bool Sirun=false;
public void isrun()
{
Sirun = !Sirun;
}
public static IsRun ft()
{
return tf;
}
}
控制物体颜色变化
using UnityEngine;
using System.Collections;
public class meh : MonoBehaviour {
IsRun irun=IsRun.ft();
private MeshRenderer mr;
void Start () {
mr = this.gameObject.GetComponent<MeshRenderer> ();
}
void Update () {
if (irun.Sirun) {
mr.material.color = new Color (0, 1, 0);
} else {
mr.material.color = new Color (1, 0, 0);
}
}
}
对单击物体的控制
using UnityEngine;
using System.Collections;
public class Script1 : MonoBehaviour {
IsRun irun = IsRun.ft();
public GameObject Gm1;
public GameObject Gm2;
public GameObject Gm3;
public GameObject light;
public float Yrotation=0.0f;
void Start () {
}
void Update () {
if (irun.Sirun) {
Gm1.transform.Translate (0.1f, 0, 0, Space.World);
Yrotation++;
Gm2.transform.eulerAngles = new Vector3 (10, Yrotation, 0);
Gm3.transform.localScale = new Vector3 (2.0f, 2.0f, 2.0f);
hight.transform.GetComponent<Light>().intensity+=8.0f;
} else {
Gm3.transform.localScale=new Vector3(1.0f,1.0f,1.0f);
light.transform.GetComponent<Light>().intensity=0.0f;
}
}
void OnMouseDown()
{
irun.isrun ();
}
}
把对应的脚本作为组件绑定到各个物体上。绑定Script1的可以控制其他物体。
Unity-->实现物体的移动
最新推荐文章于 2024-06-20 01:30:50 发布