【01】Unity

来源:互联网 发布:男士单肩包推荐 知乎 编辑:程序博客网 时间:2024/05/16 11:32

今天上午老师给我们讲了用C#对物体进行克隆,销毁下面是示例代码:先对GoCube进行克隆,然后再销毁

public class Excer_01 : MonoBehaviour {public GameObject GoCube;// Use this for initializationvoid Start () {//克隆GoCubeGameObject GOCloneCube = Instantiate (GoCube) as GameObject;//设置克隆物体的位置GOCloneCube.transform.position = new Vector3 (3, 0, 0);Destroy (GoCube,5);//5秒之后销毁GoCube}// Update is called once per framevoid Update () {}}


通过一个脚本完成:

  1. 太阳自转
  2. 地球自转 + 公转
  3. 月亮自转 + 公转

public class SunEarthMoon : MonoBehaviour {public GameObject GoSun; //太阳public GameObject GoEarth;//地球public GameObject GoMoon; //月亮public int IntSunSpeedSelf;//太阳自转速度public int IntEarthSpeedSelf;//地球自转速度public int IntEarthSpeedAround;//地球公转的速度public int IntMoonSpeedSelf;//月球自转速度public int IntMootSpeedAround;//月球公转的速度void Start () {}// Update is called once per framevoid Update () {//太阳GoSun.transform.Rotate (Vector3.up * Time.deltaTime * IntSunSpeedSelf);//地球GoEarth.transform.Rotate (Vector3.up * Time.deltaTime * IntEarthSpeedSelf);GoEarth.transform.RotateAround (GoSun.transform.position, Vector3.up, Time.deltaTime * IntEarthSpeedAround);//月亮GoMoon.transform.Rotate (Vector3.up * Time.deltaTime * IntMoonSpeedSelf);GoMoon.transform.RotateAround (GoEarth.transform.position, Vector3.up, Time.deltaTime * IntMootSpeedAround);}}

0 0
原创粉丝点击