如何统一改变球体尺寸?

时间:2016-10-14 15:31:43

标签: unity3d size

我有一个带球体的碰撞方法:

我的代码:

public class Colision : MonoBehaviour
{
    public Text points;
    int contador = 0;

    void OnCollisionEnter(Collision col)
    {
        //  GameObject halo = Instantiate(HaloPrefab) as GameObject;
        if (col.gameObject.name == "Cube")
        {
            //  Destroy (col.gameObject);
            //halo.transform.SetParent (transform, false);

            col.gameObject.SetActive(false);
            contador = contador + 1;
            points.text = "" + contador;
        }


        if (col.gameObject.name == "Cube(Clone)")
        {
            //  Destroy (col.gameObject);
            col.gameObject.SetActive(false);
            contador = contador + 1;
            points.text = "" + contador;
        }

        if (col.gameObject.name == "Cube1(Clone)")
        {
            //  Destroy (col.gameObject);
            col.gameObject.SetActive(false);
            contador = contador + 1;
            points.text = "" + contador;
        }

        if (col.gameObject.name == "Cube2(Clone)")
        {
            //  Destroy (col.gameObject);
            col.gameObject.SetActive(false);
            contador = contador + 1;
            points.text = "" + contador;
        }

        if (col.gameObject.name == "Cube3(Clone)")
        {
            //  Destroy (col.gameObject);
            col.gameObject.SetActive(false);
            contador = contador + 1;
            points.text = "" + contador;
        }
    }
}

当球体与一个块发生碰撞时,我怎么办?球体变小了?

感谢您的时间和帮助。团结对我来说更难。

1 个答案:

答案 0 :(得分:0)

您可以按如下方式修改对象的大小

示例:

//(this will make it 2x bigger)
col.transform.lossyScale *= 2; 

或者如果您只想修改单轴

// This will make it 1 unity bigger in the X axis
col.transform.lossyScale += new Vector3(1,0,0); 

自然这适用于任何transform(存在于所有游戏对象中)