Esempio n. 1
0
    void InitAI()
    {
        // cache a reference to the AI controller
        AIController = myGO.GetComponent <BaseAIController>();

        // check to see if we found an ai controller component, if not we add one here
        if (AIController == null)
        {
            AIController = myGO.AddComponent <BaseAIController>();
        }

        // initalize the AI controller
        AIController.Init();

        // tell the AI controller to go into waypoint steering mode
        AIController.SetAIState(AIStates.AIState.steer_to_waypoint);

        // disable our default input method
        default_input.enabled = false;

        // add an AI weapon controller
        gunControl = myGO.GetComponent <BaseArmedEnemy>();

        // if we don't already have a gun controller, let's add one to stop things breaking but
        // warn about it so that it may be fixed
        if (gunControl == null)
        {
            gunControl = myGO.AddComponent <BaseArmedEnemy>();
            Debug.LogWarning("WARNING! Trying to initialize car without a BaseArmedEnemy component attached. Player cannot fire!");
        }

        // tell gun controller to do 'look and destroy'
        gunControl.currentState = AIAttackStates.AIAttackState.look_and_destroy;
    }
    public virtual void Init()
    {
        // cache our transform
        myTransform = transform;

        // cache our gameObject
        myGO = gameObject;

        // cache a reference to the AI controller
        AIController = myGO.GetComponent <BaseAIController>();

        if (AIController == null)
        {
            AIController = myGO.AddComponent <BaseAIController>();
        }

        // run the Init function from our base class (BaseAIController.cs)
        AIController.Init();

        // tell AI controller that we want it to control this object
        AIController.SetAIControl(true);

        // tell our AI to follow waypoints
        AIController.SetAIState(AIStates.AIState.translate_along_waypoint_path);

        // set a flag to tell us that init has happened
        didInit = true;
    }