How to Get Sprite Dimensions in C# unity at runtime

posted in: Daily Progress, Tutorials | 0

(GameObject) _lastTrailUnit = (GameObject)Instantiate( RopeTrailGameobject, _projectileSpawner.transform.position, _projectileSpawner.transform.rotation);

// get texture width 

Transform[] ts1 = _lastTrailUnit.GetComponentsInChildren<Transform>(true);

foreachTransform t in ts1)

{

if (t.gameObject.name == “RopeTrailTexture”)

_trailunitrenderer = t.gameObject.GetComponent<SpriteRenderer>();;

}

float RopeTrailSingleUnitWidth = _trailunitrenderer.bounds.size.x;

float RopeTrailSingleUnitHeight = _trailunitrenderer.bounds.size.y;

Thanks for reading.

if you want to check out some of our projects please subscribe to our YouTube channel:

You can check up our work in progress games here:

If you are looking for solutions to game development issues see our blogs here:

If you like our projects please sign up for our newsletter at the bottom of this Page.

Leave a Reply