Question by
qudgjs12 · Dec 13, 2021 at 07:48 AM ·
scripting problemcanvas
I want to input GameObject(has camera component) to Canvas's EventCamera by using Scripts
In my game,
Players Camera is created dynamically in scene.
before start it doesn't exist in scene.
and also I can't access that camera script cause this is not a script just dll file
i want use this camera at Canvas's button's Event camera
What should I do?
this is my canvas's Inspector
and this is my whole scripts
export default class GetCamera extends ZepetoScriptBehaviour {
//private PlayerCam: UnityEngine.GameObject;
public canv: UnityEngine.Canvas;
private PlayerCam: UnityEngine.Camera;
private gmaObj: UnityEngine.GameObject; //ZepetoPlayers
private ZepetoCam1: UnityEngine.GameObject; //ZepetoCamera
private ZepetoCam2: UnityEngine.GameObject; //CameraParents
//Start() {
// this.StartCoroutine(this.getCameraFunc());
//}
OnTriggerEnter(collider) {
if (collider.tag == "Player") {
console.log("Success!!");
this.StartCoroutine(this.getCameraFunc());
}
}
*getCameraFunc() {
yield new UnityEngine.WaitForSeconds(1);
//this.PlayerCam = new UnityEngine.Camera;
//this.gmaObj = UnityEngine.GameObject.Find("ZepetoPlayers"); //ZepetoPlayers
//console.log("gmaObj name = " + this.gmaObj.name);
//this.gmaObj
//this.ZepetoCam1 = this.gmaObj.transform.GetChild(2).gameObject; //ZepetoCamera
//console.log("ZepetoCam1 name = " + this.ZepetoCam1.name);
//this.ZepetoCam2 = this.ZepetoCam1.transform.GetChild(0).gameObject; //CameraParents
//console.log("ZepetoCam2 name = " + this.ZepetoCam2.name);
//this.PlayerCam = this.ZepetoCam2.transform.GetChild(0).GetComponent<UnityEngine.Camera>();//ZepetoCamera
this.PlayerCam = UnityEngine.GameObject.Find('CameraParent').GetComponentInChildren<UnityEngine.Camera>();
//this.canv.worldCamera = this.PlayerCam.GetComponent<UnityEngine.Camera>();
//console.log("PlayerCam name = " + this.PlayerCam.name);
//console.log(this.PlayerCam.name);
//this.PlayerCam.GetComponent<UnityEngine.Camera>();
//console.log(this.name);
//this.canv.worldCamera = this.PlayerCam.GetComponent<UnityEngine.Camera>();
this.canv.worldCamera = this.PlayerCam;
//this.canv.worldCamera = UnityEngine.GameObject.Find('CameraParent').GetComponentInChildren<UnityEngine.Camera>();
console.log("Camera worked!!");
}
}
there are lots of legacy codes sorry..
I tried my best
I used typescripts
1.png
(55.8 kB)
Comment