【问题标题】:UNITY: Vector3 with doubles?UNITY:Vector3 有双打?
【发布时间】:2020-09-23 11:02:41
【问题描述】:

如果一个对象与另一个游戏对象发生碰撞,我想增加它的大小。我使用这个脚本:

 void OnTriggerEnter2D(Collider2D other)  //Unity function called when a collision is detected, and the object collided is put into the variable 'col' to be used later
 {
     if(other.gameObject.tag == "enemy")   //if the object you collided with is the enemy
     {
         transform.localScale += new Vector3 (1,1,1); //increase the size of the ball
         Destroy(other.gameObject);  //Destroy the enemy
     }
 
}
}

问题是:我想增加的对象变大到快。我试过放双打,但当然不行。有人有解决方法吗?

最好的问候 大春哥

【问题讨论】:

  • YSK 1.0 被 C# 检测为 doubleVector3 不支持。 1.0f 被检测为floatVector3 支持double 是 64 位的,对于游戏中的所有物理和图形,每帧计算多次非常昂贵。显卡可以处理 32 位 float 的变量,比 64 位 double 快很多。

标签: c# unity3d game-engine


【解决方案1】:

有几种方法。

您可以使用较小的(固定)数量来增加该值。这使用floats 而不是doubles

transform.localScale += new Vector3 (0.1f,0.1f,0.1f); // Increase size by a fixed 0.1f on all dimensions

您也可以将比例乘以浮点值

transform.localScale *= 1.1f; // increases size by 10% each time

【讨论】:

    猜你喜欢
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2021-01-04
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多