Hello im trying to set up a boat controller. basically when you get on the boat press E, controls go to the boat i was wondering if im doing something wrong.
im using a third person controller right now with a mouse controlled camera.
this is the code so far C#
using UnityEngine;
using System.Collections;
public class BoatRide : MonoBehaviour {
CharacterController cc;
CharacterMotor cm;
GameObject player;
Transform DefualtPlayerTransform;
bool isDriving=false;
// Use this for initialization
void Start () {
cc = GameObject.FindObjectOfType<CharacterController> ();
cm = GameObject.FindObjectOfType<CharacterMotor> ();
player = cm.GameObject;
DefualtPlayerTransform = player.transform.parent;
}
bool IsplayerCloseToBoat()
{
return Vector3.Distance(GameObject.transform.position,
player.transform.position)<1;
}
void SetDriving(bool isDriving)
{
this.isDriving = isDriving;
SetDriving (!isDriving);
cm.enabled = !isDriving;
cc.enabled = !isDriving;
if (isDriving)
player.transform.parent = gameObject.transform;
else
player.transform.parent = DefualtPlayerTransform;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.E) && IsPlayerCloseToBoat ())
{
}
}
}