コード例 #1
0
    public override void Init()
    {
        Debug.Log("CarController_MVD Init called.");

        // cache the usual suspects
        myBody      = GetComponent <Rigidbody>();
        myGO        = gameObject;
        myTransform = transform;

        // allow respawning from the start
        canRespawn = true;

        // save our accelMax value for later, incase we need to change it to
        // do AI catch up
        originalAccelMax = accelMax;

        // add default keyboard input if we don't already have one
        if (default_input == null)
        {
            default_input = myGO.AddComponent <Keyboard_Input>();
        }

        // cache a reference to the player controller
        myPlayerController = myGO.GetComponent <BasePlayerManager>();

        // call base class init
        myPlayerController.Init();

        // with this simple vehicle code, we set the center of mass low to try to keep the car from toppling over
        myBody.centerOfMass = new Vector3(0, -3.5f, 0);

        // see if we can find an engine sound source, if we need to
        if (engineSoundSource == null)
        {
            engineSoundSource = myGO.GetComponent <AudioSource>();
        }

        AddRaceController();

        // reset our lap counter
        raceControl.ResetLapCounter();

        // get a ref to the weapon controller
        weaponControl = myGO.GetComponent <Standard_SlotWeaponController>();

        // if a player manager is not set in the editor, let's try to find one
        if (myPlayerManager == null)
        {
            myPlayerManager = myGO.GetComponent <BasePlayerManager>();
        }

        // cache ref to data manager
        myDataManager = myPlayerManager.DataManager;

        // set default data
        myDataManager.SetName("Player");
        myDataManager.SetHealth(startHealthAmount);

        if (isAIControlled)
        {
            // set our name to an AI player
            myDataManager.SetName("AIPlayer");

            // set up AI
            InitAI();
        }

        //GameController_MVD.Instance.UpdateWrongWay(false);
    }