赞
踩
//脚本 //this当前脚本组件继承自MonoBehaviour //消息函数 void Start() void Update() //获取物体,读写其属性 //获取当前物体 GameObject obj = this.gameObject; //获取场景内其他物体 flag = GameObject.Find("红旗"); //获取位置 //this.gameObject.transform等同于this.transform Vector3 pos = this.transform.position; pos = this.transform.localPosition; //访问父子层级 this.transform.parent this.transform.parent.gameObject//获取父节点 public Transform RusCude; Transform child = RusCude.GetChild(index); //资源使用 //音频和材质,准备好材料和player public Material[] colors; public AudioClip[] musics; MeshRenderer mr; AudioSource musicPlayer; musicPlayer.clip = musics[index]; musicPlayer.Play(); mr.material = colors[index]; //物体运动 //匀速运动:根据速度设置前进距离 distance = speed * Time.deltaTime; this.transform.Translate(0, 0, distance); //运动方向 this.transform.LookAt(flag.transform); //匀速转动 this.gameObject.transform.localEulerAngles += new Vector3(0, rotationSpeed * Time.deltaTime, 0); float rotationSpeed = 120; this.transform.Rotate(0, rotationSpeed * Time.deltaTime, 0, Space.Self); //定时调用 Invoke("ChangeColor", 4);//递归用法模拟重复调用 //监听输入 Input.GetMouseButtonDown(0) Input.GetKey(KeyCode.W) //使用预制体 //实例化,使用 public GameObject bulletPre; GameObject bullet = Instantiate(bulletPre,bullets); bullet.transform.position = cannonMouth.position; bullet.transform.rotation = cannonDirection.rotation; //超类静态方法销毁 Object.Destroy(this.gameObject); //物理碰撞 //消息函数,Collider类 private void OnTriggerEnter(Collider other) //全局设置 //设置近似帧率 Application.targetFrameRate = 60; //常用类的静态属性&方法 //时间 Time.time Time.deltaTime //屏幕 Screen.width //输入 Input.mousePosition //摄像机 Camera.main.WorldToScreenPoint(this.transform.position) //数学 Random.Range(int min,int max)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。