Version: 2021.3
언어: 한국어
public Vector3 localScale ;

설명

The scale of the transform relative to the GameObjects parent.

The example below creates a sphere GameObject with a scale of (1,1,1). The application then changes the Transform.localScale from 1.0 down to 0.25 and back to 1.0 repeatedly.

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

public class Example : MonoBehaviour { private GameObject sphere; private Vector3 scaleChange, positionChange;

void Awake() { Camera.main.clearFlags = CameraClearFlags.SolidColor;

// Create a sphere at the origin. sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3(0, 0, 0);

// Create a plane and move down by 0.5. GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.transform.position = new Vector3(0, -0.5f, 0);

// Change the floor color to blue. // The blue material is present in Resources and not created in this script. Renderer rend = plane.GetComponent<Renderer>(); rend.material = Resources.Load<Material>("blue");

scaleChange = new Vector3(-0.01f, -0.01f, -0.01f); positionChange = new Vector3(0.0f, -0.005f, 0.0f); }

void Update() { sphere.transform.localScale += scaleChange; sphere.transform.position += positionChange;

// Move upwards when the sphere hits the floor or downwards // when the sphere scale extends 1.0f. if (sphere.transform.localScale.y < 0.1f || sphere.transform.localScale.y > 1.0f) { scaleChange = -scaleChange; positionChange = -positionChange; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961