【问题标题】:Get sprite prefab width获取精灵预制宽度
【发布时间】:2014-08-23 09:02:09
【问题描述】:

我有一个 预制件,它基本上是一个精灵。 它有一个 javascript 附加 & 我想得到它的宽度。

这是我的假设-

private var getObjectWidth:float;

function start(){
    // want to get the gameObject's spriteRenderer 
    var gameObjectRenderer = transform.gameObject.GetComponent(SpriteRenderer);

    // then get the width from Sprite bounds
    getObjectWidth = gameObjectRenderer.sprite.bounds.size.x;
}

【问题讨论】:

    标签: unity3d 2d unityscript


    【解决方案1】:

    http://docs.unity3d.com/ScriptReference/Renderer-bounds.html

    检查该链接。渲染器没有精灵变量

    我认为你可以使用

    gameObjectRenderer.bounds.max.x - gameObjectRenderer.bounds.min.x;
    

    或者更简单的

    gameObjectRenderer.bounds.extents;
    

    勾选这个

    http://docs.unity3d.com/ScriptReference/Bounds.html

    【讨论】:

    • 感谢您的回复。让我检查一下,详细信息。
    猜你喜欢
    • 2014-06-25
    • 2012-10-21
    • 2012-12-12
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多