Question by
Owyn99 · May 10, 2017 at 01:07 PM ·
scripting problemfpsboatmode
Problem with boat script
I got a boat script from a youtube tutorial and it works fine, the way it works is when you press 1 you go into your fps controller and when you press 2 you control the boat. The problem i have is i want it to only be able to switch when you are in a certain area, for example you have to walk up to the helm.
I tried messing around with OnTriggerEnter and Exit but im not very good at programming.
This is the script for switching modes. Any help is appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class switchMode : MonoBehaviour {
public GameObject boat;
public GameObject boatCamera;
public GameObject player;
public GameObject playerStartPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
//set to boat mode//
if(Input.GetKey ("1"))
{
boat.GetComponent<Rigidbody> ().isKinematic = false;
boat.GetComponent<boat> ().enabled = true;
boatCamera.SetActive (true);
player.SetActive (false);
}
//set to boat mode//
if(Input.GetKey("2"))
{
boat.GetComponent<Rigidbody> ().isKinematic = true;
boat.GetComponent<boat> ().enabled = false;
boatCamera.SetActive (false);
player.SetActive (true);
player.transform.position = playerStartPos.transform.position;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Problem with a ship controller script 1 Answer
HOW CAN I ADD ARMS IN FIRST PERSON SHOOTER? 0 Answers
Script creating 2 prefabs instead of 1 0 Answers
First person shooter : Leaning! 2 Answers
About mobile FPS Sprint 1 Answer