首页 > 编程语言 > 详细

Unity3D第一课之自转与公转

时间:2015-03-12 22:27:08      阅读:525      评论:0      收藏:0      [点我收藏+]

1、物体公转,即围绕一个中心物体旋转

public class gongzhuan : MonoBehaviour {

    public GameObject Axis;//轴,用于选择围绕中心

    public float RotateSpeed;//旋转速度// Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        this.transform.RotateAround (Axis.transform.position, Vector3.up,RotateSpeed);        
    }
}

  将脚本拖动到物体上(此处为gongzhuan),同时选择围绕中心物体(此处为s),填写旋转速度。

技术分享


 

2、物体自转,即以自己为中心旋转

public class zizhuan : MonoBehaviour {

    public float RotateSpeed;//旋转速度

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        transform.Rotate(Vector3.down* RotateSpeed,Space.World);
    }
}

  将脚本拖动到物体上(此处为zizhuan),填写旋转速度。

技术分享

 

Unity3D第一课之自转与公转

原文:http://www.cnblogs.com/hehaiyang/p/4333841.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!