我想"挤压"一个gameObject。当距离开始为6.98时,执行以下代码:" gameObject1和gameObject2之间的距离越小,此游戏对象越薄越长#34;。不知何故,这段代码没有效果。为什么呢?
public Transform gameObject1;
public Transform gameObject2;
void Update ()
{
float distance_squeeze = Vector3.Distance(gameObject1.position, gameObject2.position);
for (distance_squeeze = 6.98f; distance_squeeze > 0; distance_squeeze -= 0.1f)
{
transform.localScale += new Vector3(-0.5F, 0.5F, 0);
}
}
答案 0 :(得分:1)
您正在计算gameObject1
和gameObject2
之间的距离,然后将其设置为6.98
。
尝试类似:
void Update ()
{
float distance_squeeze = Vector3.Distance(gameObject1.position, gameObject2.position);
if(distance_squeeze < 6.98F){
transform.localScale = new Vector3(-distance_squeeze, distance_squeeze, 1);
}
}