How to create a script for moving a 3rd person controller in an iOS device by using Javascript in Unity3D?

Posted by user36563 on Game Development See other posts from Game Development or by user36563
Published on 2013-10-31T08:39:18Z Indexed on 2013/10/31 10:23 UTC
Read the original article Hit count: 198

Filed under:

I've a code but I'm not sure about the steps, so what I should do after the script?

pragma strict

public var horizontalSpeed : float = 1.0; public var verticalSpeed : float = 1.0;

private var h : float = 0.0; private var v : float = 0.0;

private var lastPos : Vector3 = Vector3.zero;

function Update() {

if UNITY_EDITOR

if ( Input.GetMouseButtonDown(0) )
{
    lastPos = Input.mousePosition;
}
else if ( Input.GetMouseButton(0) )
{
    var delta = Input.mousePosition - lastPos;

        h = horizontalSpeed * delta.x ;
        transform.Rotate( 0, -h, 0, Space.World );

        v = verticalSpeed * delta.y ;
        transform.position += transform.forward * v * Time.deltaTime;

    lastPos = Input.mousePosition;
}

else

if (Input.touchCount == 1)
{
    var touch : Touch = Input.GetTouch(0);

    if (touch.phase == TouchPhase.Moved)
    {
        h = horizontalSpeed * touch.deltaPosition.x ;
        transform.Rotate( 0, -h, 0, Space.World );

        v = verticalSpeed * touch.deltaPosition.y ;
        transform.position += transform.forward * v * Time.deltaTime;
    }
}

endif

}

© Game Development or respective owner

Related posts about unity