unity中实现图片宽度和相机宽度相同

public class platform : MonoBehaviour
{
    private void Start()
    {
        Resize();
    }
    void Resize()
    {
        float width = GetComponent<SpriteRenderer>().bounds.size.x;
        Vector3  scale = transform.localScale  ;
        scale.x = (Camera.main.orthographicSize * 2 / Screen.height * Screen.width) / width;//屏幕宽/屏幕高=相机宽/相机高,相机宽=图片宽*图片在x轴的缩放系数
        transform.localScale = scale;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40323256/article/details/88637826