Zepeto Follow UIGauge
Zepeto 2022. 4. 15. 00:37반응형
import { ZepetoScriptBehaviour } from 'ZEPETO.Script'
import { Camera, GameObject, Transform, Vector3, Vector2, RectTransformUtility, RectTransform} from "UnityEngine"
import { Slider } from "UnityEngine.UI"
export default class UIHpGauge extends ZepetoScriptBehaviour {
public target: Transform;
public sldier: Slider;
public canvasRect : RectTransform;
private zepetoCam : Camera;
public Init(target : Transform)
{
this.target = target;
this.zepetoCam = GameObject.Find("ZepetoCamera").GetComponent<Camera>();
}
Update()
{
if(this.target != null){
// Calculate *screen* position (note, not a canvas/recttransform position)
var canvasPos = $ref<Vector2>();
var screenPoint: Vector3 = this.zepetoCam.WorldToScreenPoint(this.target.position);
// Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.canvasRect, new Vector2(screenPoint.x, screenPoint.y + 120), null, canvasPos);
var tpos = $unref(canvasPos);
// Set
this.sldier.transform.localPosition = new Vector3(tpos.x, tpos.y, 0);
//Debug.Log(canvasPos);
}
}
}
반응형
'Zepeto' 카테고리의 다른 글
제페토 모바일 GetComponent 에러 (4) | 2022.05.13 |
---|---|
제페토 월드 모바일 접속 안될때 방화벽 해제 (0) | 2022.04.14 |
유니티로 만드는 제페토 월드 (회전 동기화) (0) | 2022.04.13 |
제페토 월드 만들기 (회전 동기화) (0) | 2022.04.11 |
찰칵 (0) | 2022.03.31 |