GMU:Tutorials/NETWORKING/CONTROLLING THE CAMERA IN UNITY WITH THE CAPTURY: Difference between revisions
Junyuan WU (talk | contribs) No edit summary |
Junyuan WU (talk | contribs) No edit summary |
||
Line 45: | Line 45: | ||
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> | <br> | ||
<source lang="Java" line start= " | <source lang="Java" line start= "1"> | ||
using UnityEngine; | using UnityEngine; | ||
using System.Collections; | using System.Collections; |
Revision as of 16:06, 31 July 2016
1.open unity and create a new Unity project.
2. create a simple Unity scene.
For the purposes of this tutorial, it is recommended to creating a simple plane and shape objects.
here I create a cube and a sphere.
3. add component to camera
select camera in hierarchy,single click it.
click the right of table to add component to the camera.
select a new script
enter a name for this script
double click the script in Assets,then you will get a script widow, you can write code in it.
4.write the code.
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.
<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; } } }
Then in the right table, you can set the remote IP and the port of the main computer.