Unity-Why can not change the view of main Camera into a position of the GameObject?

Unity-Why can not change the view  of main Camera into a position of the GameObject?



A:For change the position  of main camera. You should
(1)select the main camera with Camera class
using the following code:
Camera cam=Camera.main;
(2)change the position. 
Notice that when you change the localPosition (position which is relative to the parent GameObject)
You should add it to fix the position.


Here is my code:
cam = Camera.main;
offset=Unitychan_GameObject.transform.localPosition+UnitychanFace_GameObject.transform.localPosition+this.transform.localPosition;
 cam.transform.localPosition = UnitychanEyes_GameObject.transform.localPosition + offset;

P.S.
localPosition  is a Position which is relative to parent GameObject.

Comments

Popular posts from this blog

GameObject.SetActive() v.s. GameObject.active

output message to Unity Console - Debug.Log() v.s. Debug.LogWarning() v.s. Debug.LogError() v.s. print()