void Start()
 {
     transform.tag = "Player";
     cameraFPS     = GetComponentInChildren(typeof(Camera)).transform.gameObject;
     cameraFPS.transform.localPosition = new Vector3(0, 1, 0);
     cameraFPS.transform.localRotation = Quaternion.identity;
     cameraFPS.tag     = "MainCamera";
     controller        = GetComponent <CharacterController> ();
     joystickMoveFPS   = transform.Find("Canvas/JoystickMFPS").GetComponent <JoystickFree>();
     joystickRotateFPS = transform.Find("Canvas/JoystickRFPS").GetComponent <JoystickFree>();
     sceneControllerMS = FindObjectOfType(typeof(MSSceneControllerFree)) as MSSceneControllerFree;
 }
Example #2
0
    void Awake()
    {
        error = false;
        CheckEqualKeyCodes();
        MSSceneControllerFree[] sceneControllers = FindObjectsOfType(typeof(MSSceneControllerFree)) as MSSceneControllerFree[];
        if (sceneControllers.Length > 1)
        {
            Debug.LogError("Only one controller is allowed per scene, otherwise the controllers would conflict with each other.");
            error = true;
            for (int x = 0; x < sceneControllers.Length; x++)
            {
                sceneControllers [x].gameObject.SetActive(false);
            }
        }
        if (startingVehicle >= vehicles.Length)
        {
            error = true;
            Debug.LogError("Vehicle selected to start does not exist in the 'vehicles' list");
        }
        if (vehicles.Length == 0)
        {
            error = true;
            Debug.LogError("There is no vehicle in the scene or no vehicle has been associated with the controller.");
        }
        for (int x = 0; x < vehicles.Length; x++)
        {
            if (vehicles [x])
            {
                if (!vehicles [x].GetComponent <MSVehicleControllerFree> ())
                {
                    error = true;
                    Debug.LogError("The vehicle associated with the index " + x + " does not have the 'MSVehicleController' component. So it will be disabled.");
                }
            }
            else
            {
                error = true;
                Debug.LogError("No vehicle was associated with the index " + x + " of the vehicle list.");
            }
        }
        if (error)
        {
            for (int x = 0; x < vehicles.Length; x++)
            {
                if (vehicles [x])
                {
                    MSVehicleControllerFree component = vehicles [x].GetComponent <MSVehicleControllerFree> ();
                    if (component)
                    {
                        component.disableVehicle = true;
                    }
                    vehicles [x].SetActive(false);
                }
            }
            return;
        }
        else
        {
            //UI transform.find
            cameraMobileButton = transform.Find("Canvas/ChangeCamerasB").GetComponent <Button> ();
            enterAndExitButton = transform.Find("Canvas/EnterAndExitB").GetComponent <Button> ();

            buttonLeft     = transform.Find("Canvas/MSButtonLeft").GetComponent <MSButtonFree> ();
            buttonRight    = transform.Find("Canvas/MSButtonRight").GetComponent <MSButtonFree> ();
            buttonUp       = transform.Find("Canvas/MSButtonUp").GetComponent <MSButtonFree> ();
            buttonDown     = transform.Find("Canvas/MSButtonDown").GetComponent <MSButtonFree> ();
            joystickCamera = transform.Find("Canvas/MSJoystickCamera").GetComponent <JoystickFree> ();



            kmhText = transform.Find("Canvas/Strings/kmhText").GetComponent <Text> ();
            if (Application.loadedLevelName == "SimuladorJaviXue")
            {
                Boton    = transform.Find("Canvas/ButtonRecord/Text").GetComponent <Text> ();
                entrenar = transform.Find("Canvas/Strings/entrenar").GetComponent <Text> ();
            }
            volantText = transform.Find("Canvas/Strings/volantText").GetComponent <Text> ();

            backGround = transform.Find("Canvas/Strings").GetComponent <Image> ();
            //end transform.find

            if (nextVehicle)
            {
                nextVehicle.onClick = new Button.ButtonClickedEvent();
                nextVehicle.onClick.AddListener(() => NextVehicle());
            }
            if (previousVehicle)
            {
                previousVehicle.onClick = new Button.ButtonClickedEvent();
                previousVehicle.onClick.AddListener(() => PreviousVehicle());
            }

            if (cameraMobileButton)
            {
                cameraMobileButton.onClick = new Button.ButtonClickedEvent();
                cameraMobileButton.onClick.AddListener(() => Mobile_CameraInput());
            }
            if (enterAndExitButton)
            {
                enterAndExitButton.onClick = new Button.ButtonClickedEvent();
                enterAndExitButton.onClick.AddListener(() => Mobile_EnterAndExitVehicle());
            }

            vehicleCode = vehicles [currentVehicle].GetComponent <MSVehicleControllerFree> ();
            EnableOrDisableButtons(vehicleCode.isInsideTheCar);

            Time.timeScale   = 1;
            enterAndExitBool = false;
            sceneName        = SceneManager.GetActiveScene().name;
            currentVehicle   = startingVehicle;
            //
            for (int x = 0; x < vehicles.Length; x++)
            {
                if (vehicles [x])
                {
                    vehicles [x].GetComponent <MSVehicleControllerFree> ().isInsideTheCar = false;
                }
            }
            playerIsNull = false;
            if (player)
            {
                player.SetActive(false);
            }
            else
            {
                playerIsNull = true;
            }
            if (startInPlayer)
            {
                if (player)
                {
                    player.SetActive(true);
                }
                else
                {
                    startInPlayer = false;
                    if (vehicles.Length > startingVehicle && vehicles [currentVehicle])
                    {
                        vehicles [startingVehicle].GetComponent <MSVehicleControllerFree> ().isInsideTheCar = true;
                    }
                }
            }
            else
            {
                if (vehicles.Length > startingVehicle && vehicles [currentVehicle])
                {
                    vehicles [startingVehicle].GetComponent <MSVehicleControllerFree> ().isInsideTheCar = true;
                }
            }
        }
    }