unity ugui 伤害飘血

    public virtual void OnUpdate()
    {
        if (_thissprite.goRoot.hudTrm == null)
            return;
        this._startWorldPos = _thissprite.goRoot.hudTrm.position + offsetVec;
        var screenPos = this.getScreenPos(this._mainCamera, this._startWorldPos);
        this.transform.localPosition = new Vector3(screenPos.x + this._xOffset, screenPos.y, 0);
    }
   // 将精灵的世界坐标转换成屏幕坐标
    public Vector3 getScreenPos(Camera cam, Vector3 worldPos)
    {
        var resolutionX = this._canvasScaler.referenceResolution.x;
        var resolutionY = this._canvasScaler.referenceResolution.y;
        var offset = (Screen.width / this._canvasScaler.referenceResolution.x) * (1 - this._canvasScaler.matchWidthOrHeight) + (Screen.height / this._canvasScaler.referenceResolution.y) * this._canvasScaler.matchWidthOrHeight;
        var screenPos = RectTransformUtility.WorldToScreenPoint(cam, worldPos);
        return new Vector3(screenPos.x / offset, screenPos.y / offset, 0);
    }

你可能感兴趣的:(Unity)