Unity设置物体移动、缩放和旋转

本文介绍了一个使用Unity进行物体操作的简单示例,包括移动、缩放、旋转物体等基本功能,并展示了如何通过GUI按钮触发这些操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class C_3_6 : MonoBehaviour {
    public GameObject cube;
    public GameObject cylinder;

    void OnGUI() {
        if (GUILayout.Button ("向左移动物体")) {
            cube.transform.Translate (new Vector3(-0.5f, 0f, 0f));
        }
        if (GUILayout.Button ("向右移动物体")) {
            cube.transform.position = cube.transform.position + new Vector3 (0.5f, 0f, 0f);
        }
        if (GUILayout.Button ("放大物体")) {
            cube.transform.localScale *= 1.2f;
        }
        if (GUILayout.Button ("缩小物体")) {
            cube.transform.localScale *= 0.8f;
        }
        if (GUILayout.Button ("旋转物体")) {
            cube.transform.Rotate (new Vector3(0, 10, 0));
        }
        if (GUILayout.Button ("围绕球体旋转物体")) {
            cube.transform.RotateAround (cylinder.transform.position, Vector3.up, 10);
        }
    }

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值