I’m trying to create a scene in which when the player reaches near a boat and presses ‘f’ , main camera switches to boat camera to simulate a “you have entered the boat” , My boat also moves according to a,w,s,d keys but the problem is whenever I press f the camera switches but the movement of boat doesn’t take place.
Here is the script:
#pragma strict
var moveSpeedX:float=50;
var moveSpeedZ:float = 80;
private var player1:GameObject;
var desiredDistance:float =5;
@HideInInspector
static var boatCam:Camera;
@HideInInspector
static var mainCam:Camera;
private var guiOn:boolean;
function Awake() {
player1 = GameObject.FindWithTag("MainCamera");
boatCam = GameObject.FindWithTag("Boat Cam").camera;
mainCam = GameObject.FindWithTag("MainCamera").camera;
mainCam.active = true;
boatCam.active = false;
}
function Update () {
//Distance Calculation
var dist:float = Vector3.Distance(transform.position , player1.transform.position);
if(dist<desiredDistance && Input.GetKeyDown(KeyCode.F))
{
//GUI On
guiOn = true;
//Camera Switching
mainCam.active = false;
boatCam.active = true;
// Movement
var amtToMoveX = (moveSpeedX/rigidbody.mass)*Input.GetAxis("Horizontal");
amtToMoveX*=Time.deltaTime;
var amtToMoveZ = (moveSpeedZ/rigidbody.mass)*Input.GetAxis("Vertical");
amtToMoveZ*=Time.deltaTime;
rigidbody.velocity = Vector3(amtToMoveX,0,amtToMoveZ);
}
guiOn = false;
}