1

我正在尝试“挤压”一个游戏对象。当距离开始为 6.98 时,执行以下代码:“gameObject1 和 gameObject2 之间的距离越小,这个 gameObject 越细越长”。不知何故,这段代码没有任何效果。为什么?

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);
     }
}
4

1 回答 1

1

您正在计算 和 之间的距离gameObject1gameObject2然后将其设置为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);
     }   
 }
于 2015-10-26T06:49:59.657 回答