unity3d 中实现物体的移动

5 篇文章 0 订阅

单例

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 (010);
        } else {
            mr.material.color = new Color (100);
        }
    }
}

对单击物体的控制

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.1f00Space.World);
                        Yrotation++;
                        Gm2.transform.eulerAngles = new Vector3 (10Yrotation0);
                        Gm3.transform.localScale = new Vector3 (2.0f2.0f2.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的可以控制其他物体。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值