コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        flagTookOutWep = false;

        dissolveAnim    = GetComponent <DissolveAnim>();
        playerTransform = FindObjectOfType <PlayerController>().transform;
        if (playerTransform == null)
        {
            playerTransform = FindObjectOfType <PlayerController>().transform;
        }

        capsuleCollider = GetComponent <CapsuleCollider>();


        navMeshAgent = GetComponent <NavMeshAgent>();
        stateMachine = new AiStateMachine(this);
        ragdoll      = GetComponentInChildren <RagdollController>();
        healthBar    = GetComponentInChildren <UIHealthBar>();
        weapons      = GetComponent <AiWeapons>();

        // registering states
        stateMachine.RegisterState(new AiChasePlayerState());
        stateMachine.RegisterState(new AiDeathState());
        stateMachine.RegisterState(new AiIdleState());
        stateMachine.RegisterState(new AiFindWeaponState());
        stateMachine.RegisterState(new AiAttackPlayerState());

        stateMachine.ChangeState(initState);

        _playerHealth = playerTransform.GetComponent <PlayerHealth>();
        _flagIsAlive  = true;
    }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            returnWeaponID();
            Destroy(gameObject, 0.1f);
        }

        HitBox hitBox = other.gameObject.GetComponent <HitBox>();

        if (hitBox)
        {
            AiWeapons weapons = hitBox.health.GetComponent <AiWeapons>();
            if (weapons != null)
            {
            }
        }
    }
コード例 #3
0
    // AI
    private void OnTriggerEnter(Collider other)
    {
        PlayerController pc = other.GetComponent <PlayerController>();

        if (pc)
        {
            _ac.PlayOneShot(footstepsSounds[Random.Range(0, footstepsSounds.Length)]);
        }

        AiWeapons aiWeapon = other.gameObject.GetComponent <AiWeapons>();

        if (aiWeapon)
        {
            if (aiWeapon.hasWeapon)
            {
                return;
            }
            RaycastWeapon newWeapon = Instantiate(weaponFab);
            aiWeapon.EquipWeapon(newWeapon);
            aiWeapon.pickedUpWeapon = true;
            Destroy(gameObject);
        }
    }