unity ugui 伤害飘血

来源:互联网 发布:sqlserver服务管理器 编辑:程序博客网 时间:2024/06/10 09:14
    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);    }

0 0
原创粉丝点击