71
edits
Junyuan WU (talk | contribs) (Created page with "== 1.open unity and create a new Unity project.== thumb|left|800px <br style="clear:both"> == 2. create a simple Unity scene.== For the purposes of...") |
Junyuan WU (talk | contribs) No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 44: | Line 44: | ||
this code is for camera, then create a gameobject, this gameobject is the cube, the capture system will send the position of the root bone to the cube, then the script will make the camera follow the cube. | this code is for camera, then create a gameobject, this gameobject is the cube, the capture system will send the position of the root bone to the cube, then the script will make the camera follow the cube. | ||
<br> | |||
<source lang="Java" line start= "1"> | |||
using UnityEngine; | |||
using System.Collections; | |||
public class CameraFollow : MonoBehaviour { | |||
public GameObject target; | |||
public bool orBitY = false; | |||
private Vector3 positionoffset = Vector3.zero; | |||
// Use this for initialization | |||
void Start () { | |||
positionoffset = transform.position - target.transform.position ; | |||
} | |||
// Update is called once per frame | |||
void Update () { | |||
if (target != null) { | |||
transform.LookAt (target.transform); | |||
if (orBitY) | |||
transform.RotateAround (target.transform.position, Vector3.up, Time.deltaTime); | |||
transform.position = target.transform.position + positionoffset; | |||
} | |||
} | |||
} | |||
</source> | |||
[[Image:code.png|thumb|left|800px]] | [[Image:code.png|thumb|left|800px]] | ||
<br style="clear:both"> | <br style="clear:both"> |
edits