【发布时间】:2016-03-10 09:20:42
【问题描述】:
我制作了一个带有刚体组件的预制游戏对象。 每当我从检查器更改原始预制件的质量时,场景中存在的所有实例都会受到影响(该字段不会被覆盖)。但是当我尝试使用脚本做同样的事情时,实例的质量保持不变(只有主预制件受到影响,每次我进入播放模式时,它都会保留之前的值!)。该脚本附加到另一个游戏对象,如下所示:
using UnityEngine;
using System.Collections;
public class CubeScript : MonoBehaviour {
public GameObject largeCube; // dragged the original prefab in the inspector
private Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = (Rigidbody) largeCube.GetComponent ("Rigidbody");
rb.mass = 44; // this is not changing the instances, rather only the main prefab. Note that the mass is not overridden
}
}
作为初学者,我不明白。请给我解释一下。
【问题讨论】:
-
你可以试试
rb = largeCube.GetComponent<RigidBody>()吗?
标签: c# unity3d game-engine unity5