- Home /
Duplicate of http://answers.unity3d.com/questions/1236515/google-vr-how-do-i-use-cameramaintransformforward-1.html
Unity JavaScript - Camera.main.tranform.forward? (NOOB)
Hello I am working with a free FPSkit. I'm attempting to customize the assets for mobile VR (GoogleVR).
My main issue is with the "Main Camera" forward movement.
I recently had the same issue with another project. Then, I was using the "Standard Assets" "FPSCharacterController" and I changed line "100" to..
Vector3 desiredMove = Camera.main.transform.forward*m_Input.y + Camera.main.transform.right*m_Input.x;
This allowed me to always move the player in the forward direction of the "Main Camera", which is exactly what I wanted.
My issue now is that I am not using the Standard Assets and this new projects "FPS Camera Script" is written in JS.
/** Script written by OMA [www.armedunity.com] */
var maxRayDistance = 2.0; var layerMask : LayerMask; var mySkin : GUISkin; var showGui : boolean = false;
function Update() { var direction = gameObject.transform.TransformDirection(Vector3.forward); var hit : RaycastHit; var position = transform.position; if (Physics.Raycast(position, direction, hit, maxRayDistance, layerMask.value)) { showGui = true; if(Input.GetButtonDown("Use")) { var target = hit.collider.gameObject; target.BroadcastMessage("Action"); }
}else{ showGui = false; } }
function OnGUI(){ GUI.skin = mySkin; if(showGui){ GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/1.4),800,100),"Press key >>E<< to Use");
} }
I am a NOOB, with no real coding experience. But, I'm assuming I have to change this line ---
var direction = gameObject.transform.TransformDirection(Vector3.forward);
All I can find are C# references using "Camera.main.transform.forward". So how would I go about this in JS??
Any help is greatly appreciated, Thank you.
Scott, the NOOB.