Наследование: MonoBehaviour
Пример #1
0
 void Start()
 {
     // Set default values here
     currentTarget = null;
     GetComponent <TeamPlayer>().pointsValue = 1; // PlayerScores.killBotTankBonus;
     aiFollow = GetComponent <AIFollow>();
 }
Пример #2
0
    public void Start()
    {
        // получаем компоненты у игрока и его характеристики
        PlCh = GameObject.Find("-Characteristics-").GetComponent<PlayerCharacteristics>();

        myPathfinder = GetComponent<AIFollow>();
        my = GetComponent<npcCharacteristics>();
        myAnimator = myBody.GetComponent<Animator>();
        myBehaviour = GetComponent<Behaviour>();
        myEnemySearch = GetComponent<EnemySearchProtocol>();
        aggressivePlayer = GetComponent<EnemyAttack>();

        // Получаем контроллер
        _controller = GetComponent<CharacterController>();

        // Получаем компонент трансформации объекта, к которому привязан данный компонент
        myTransform = transform;

        // Получаем компонент трансформации игрока
           	myEnemyTransform = GameObject.Find("GLOBAL").transform;

        myModel = transform.GetChild(0);

        //выключаем пасфайндер, чтобы не ходил пока
        Walk(false);
    }
Пример #3
0
 void Start()
 {
     c = GetComponent<CharacterController>();
     ai = GetComponent<AIFollow>();
     ai.enabled = false;
     player = GameObject.FindGameObjectWithTag("Player");
     Target = new GameObject();
 }
Пример #4
0
 void Start()
 {
     c          = GetComponent <CharacterController>();
     ai         = GetComponent <AIFollow>();
     ai.enabled = false;
     player     = GameObject.FindGameObjectWithTag("Player");
     Target     = new GameObject();
 }
Пример #5
0
    void Start()
    {
        eye          = transform.Find("Hips/Spine/Spine1/Spine2/Neck/Neck1/Head/RightEye");
        followScript = GetComponent(typeof(AIFollow)) as AIFollow;

        // validate component references
        if (computer == null)
        {
            computer = GetComponent(typeof(RootMotionComputer)) as RootMotionComputer;
        }
        if (character == null)
        {
            character = GetComponent(typeof(CharacterController)) as CharacterController;
        }
        if (victim == null)
        {
            victim = GameObject.Find("Main Camera");
        }
        if (followScript.target == null)
        {
            followScript.target = GameObject.Find("Main Camera").transform;
        }

        lastInterval = Time.realtimeSinceStartup;

        // tell the computer to just output values but not apply motion
        computer.applyMotion = false;
        // tell the computer that this script will manage its execution
        computer.isManagedExternally = true;
        // since we are using a character controller, we only want the z translation output
        computer.computationMode = RootMotionComputationMode.ZTranslation;
        // initialize the computer
        computer.Initialize();

        // set up properties for the animations
        animation["idle"].layer        = 0; animation["idle"].wrapMode = WrapMode.Loop;
        animation["walk01"].layer      = 1; animation["walk01"].wrapMode = WrapMode.Loop;
        animation["run"].layer         = 1; animation["run"].wrapMode = WrapMode.Loop;
        animation["attack"].layer      = 3; animation["attack"].wrapMode = WrapMode.Once;
        animation["headbutt"].layer    = 3; animation["headbutt"].wrapMode = WrapMode.Once;
        animation["scratchidle"].layer = 3; animation["scratchidle"].wrapMode = WrapMode.Once;
        animation["walk02"].layer      = 3; animation["walk02"].wrapMode = WrapMode.Once;
        animation["standup"].layer     = 3; animation["standup"].wrapMode = WrapMode.Once;

        // Load audio
        //audio.clip = Resources.Load("zombie_moan1.mp3") as AudioClip;
        //audio.Play();
        variableInterval = updateInterval;

        //animation.Play("idle");
        Walk();
    }
	void Start()
	{
		eye = transform.Find("Hips/Spine/Spine1/Spine2/Neck/Neck1/Head/RightEye");
		followScript = GetComponent(typeof(AIFollow)) as AIFollow;
		
		// validate component references
		if (computer == null) computer = GetComponent(typeof(RootMotionComputer)) as RootMotionComputer;
		if (character == null) character = GetComponent(typeof(CharacterController)) as CharacterController;
		if (victim == null) victim = GameObject.Find("Main Camera");
		if (followScript.target == null) followScript.target = GameObject.Find("Main Camera").transform;
		
		lastInterval = Time.realtimeSinceStartup;
		
		// tell the computer to just output values but not apply motion
		computer.applyMotion = false;
		// tell the computer that this script will manage its execution
		computer.isManagedExternally = true;
		// since we are using a character controller, we only want the z translation output
		computer.computationMode = RootMotionComputationMode.ZTranslation;
		// initialize the computer
		computer.Initialize();
		
		// set up properties for the animations
		animation["idle"].layer = 0; animation["idle"].wrapMode = WrapMode.Loop;
		animation["walk01"].layer = 1; animation["walk01"].wrapMode = WrapMode.Loop;
		animation["run"].layer = 1; animation["run"].wrapMode = WrapMode.Loop;
		animation["attack"].layer = 3; animation["attack"].wrapMode = WrapMode.Once;
		animation["headbutt"].layer = 3; animation["headbutt"].wrapMode = WrapMode.Once;
		animation["scratchidle"].layer = 3; animation["scratchidle"].wrapMode = WrapMode.Once;
		animation["walk02"].layer = 3; animation["walk02"].wrapMode = WrapMode.Once;
		animation["standup"].layer = 3; animation["standup"].wrapMode = WrapMode.Once;
		
		// Load audio
		//audio.clip = Resources.Load("zombie_moan1.mp3") as AudioClip;
		//audio.Play();
		variableInterval = updateInterval;
		
		//animation.Play("idle");
		Walk();
		
	}
Пример #7
0
    // Use this for initialization
    void Start()
    {
        CurrHealth = MaxHealth;

        AI = GetComponent <AIFollow>();
    }
Пример #8
0
    IEnumerator CoUpdate()
    {
        myTransform = this.transform;
        baseYPosition = myTransform.localPosition.y;
        if(meleeRange == null)
            meleeRange = myTransform.GetComponentInChildren(typeof(MeleeArc)) as MeleeArc;

        if(seek == null)
                seek = GetComponent(typeof(AIFollow)) as AIFollow;

        if(movement == null)
            movement = GetComponent(typeof(CharacterController)) as CharacterController;

        yield return new WaitForSeconds(2f);
        //Initialize AI
        while(true)
        {
            if(myHealth.IsDead)
            {
                behave = AIBehavior.die;
            }
            else
            {
                Vector3 horizontalVelocity = new Vector3(movement.velocity.x, 0, movement.velocity.z);
                if(horizontalVelocity.magnitude > 0.1f )
                {
                    if(horizontalVelocity.magnitude > 2.5f)
                        animations.CrossFade(runAnimation);
                    else
                        animations.CrossFade(walkAnimation);
                }
                else
                    animations.CrossFade(idleAninimation);

                if(CanSeePlayer() || myTarget != null)
                {
                    stillLooking = true;
                    if(CanSeePlayer() )
                    {
                        countTilLostTarget = 0;
                    }
                    if(!CanSeePlayer() || !InMeleeRange())
                        FlipForward();
                    else
                        behave = AIBehavior.attack;
                }
                if(!CanSeePlayer() && myTarget != null && stillLooking && switchedDirections)
                {
                    StartCoroutine(FlipDirectionDelay() );
                    switchedDirections = false;
                    forwardDirection.eulerAngles = new Vector3(0, forwardDirection.eulerAngles.y*yRotationMod, 0);
                    if( (forwardDirection.eulerAngles.y < -80 || forwardDirection.eulerAngles.y > 240) && forwardDirection.eulerAngles.z < 100)
                    {
                        forwardDirection.eulerAngles = new Vector3(0, forwardDirection.eulerAngles.y, 180);
                    }
                    else
                    {
                        forwardDirection.eulerAngles = new Vector3(0, forwardDirection.eulerAngles.y, 0);
                    }
                }
                else if(countTilLostTarget >= lostTargetNumber)
                {
                    myTarget = null;
                }

                forwardDirection.position = myTransform.position;

            }
            //Debug.Log("State: "+ ((AIBehavior) behave).ToString("F") );
            switch(behave)
            {
            case AIBehavior.idle:
                StartCoroutine(Idle() );
                break;
            case AIBehavior.pursue:
                StartCoroutine(Pursue() );
                break;
            case AIBehavior.attack:
                StartCoroutine(Attack() );
                break;
            case AIBehavior.flee:
                StartCoroutine(Flee() );
                break;
            case AIBehavior.die:
                StartCoroutine(Die() );
                break;
            }
            yield return new WaitForSeconds(updateDelayTime);
        }
    }
Пример #9
0
 void Start()
 {
     aiFollow = GetComponent <AIFollow>();
     itemDrop = GetComponent <ItemDrop>();
 }
Пример #10
0
    void Start()
    {
        aiFollow = GetComponent<AIFollow>();

        workWaypoints = new List<GameObject>(GameObject.FindGameObjectsWithTag("WorkWaypoint"));
        wanderWaypoints = new List<Vector3>();

        while (wanderWaypoints.Count < wanderListSize) {
            wanderWaypoints.Add(new Vector3(Random.Range(-50, 50), 0, Random.Range(-50, 50)));
        }

        workWaypointIndex = 0;
        wanderWaypointIndex = 0;
        assignedTarget = false;

        //When an agent spawns, he should start by wandering
        aState = agentState.Wandering;
    }