Exemplo n.º 1
0
    private void Update()
    {
        transform.position += transform.up * speed * Time.deltaTime;
        if (Time.time > lifeTime)
        {
            Destroy(gameObject);
        }



        RaycastHit2D rayHit = Physics2D.Raycast(transform.position, transform.up);

        if (rayHit.collider == null)
        {
            return;
        }
        if ((rayHit.transform.position - transform.position).magnitude < 3f)
        {
            switch (rayHit.collider.tag)
            {
            case "Enemy":
                AIHealth aiHealth = rayHit.collider.GetComponent <AIHealth>();
                aiHealth.Damage(damage);
                Destroy(gameObject);
                break;

            case "Destructible":
                Destructible destructible = rayHit.collider.GetComponent <Destructible>();
                destructible.TakeDamage(damage);
                Destroy(gameObject);
                break;
            }
        }
    }
    public override void VisualOnActivate()
    {
        AIHealth health = (AIHealth)refManager.health;

        health.SetLimbsActive(true);
        refManager.animManager.Attack();
    }
    public override void VisualOnDeactivate()
    {
        AIHealth health = (AIHealth)refManager.health;

        health.SetLimbsActive(false);
        refManager.animManager.StopAttack();
    }
Exemplo n.º 4
0
    public void ResetEncounter()
    {
        if (!encounterSpawned)
        {
            return;
        }
        foreach (GameObject go in activeEnemies)
        {
            AIHealth health = go.GetComponent <AIHealth>();
            if (health != null)
            {
                health.DestroyEnemy();
            }
            else
            {
                Destroy(go);
            }
        }

        activeEnemies.Clear();

        for (int i = 0; i < doors.Count; i++)                  // remove later
        {
            doors[i].ChangeLockState(false);
        }

        doorsLocked      = false;
        encounterSpawned = false;
    }
Exemplo n.º 5
0
    private void OnCollisionEnter(Collision other)
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, botMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Transform targetTransform = colliders[i].GetComponent <Transform>();

            if (!targetTransform)
            {
                continue;
            }

            AIHealth   targetHealth = targetTransform.GetComponent <AIHealth>();
            BotManager botManager   = targetTransform.GetComponent <BotManager>();
            if (!targetHealth || !botManager)
            {
                continue;
            }
            targetHealth.TakeDamage(Weapon.TakeDamage);
            botManager.isOnAttack = true;
            break;
        }

        StartCoroutine(DestroyTimer());
    }
Exemplo n.º 6
0
    void Awake()
    {
        // Class

        m_AIHealth   = GetComponent <AIHealth> ();
        m_Animator   = GetComponent <Animator> ();
        m_AIMovement = GetComponent <AIMovement> ();
    }
 public void Initialize(AIAgent agent)
 {
     _aiWeapon          = agent.GetComponent <AIWeapons>();
     _navAgent          = agent.GetComponent <NavMeshAgent>();
     _aiHealth          = agent.GetComponent <AIHealth>();
     _fov               = agent.GetComponent <FieldOfView>();
     _lastKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();
     _agent             = agent;
 }
Exemplo n.º 8
0
    protected virtual void Awake()
    {
        _navMeshAgent = GetComponent <NavMeshAgent>();
        _animator     = GetComponent <Animator>();
        _aiHealth     = GetComponent <AIHealth>();

        bones = GetComponentsInChildren <Rigidbody>();

        SwitchBones(true);
    }
Exemplo n.º 9
0
    public void Initialize(AIAgent agent)
    {
        _navAgent     = agent.GetComponent <NavMeshAgent>();
        _aiHealth     = agent.GetComponent <AIHealth>();
        _aiWeapon     = agent.GetComponent <AIWeapons>();
        _coversInZone = agent.GetComponentInParent <CombatZone>().CoversInZone.ToArray();

        _anim  = agent.GetComponent <Animator>();
        _agent = agent;
    }
Exemplo n.º 10
0
 void Awake()
 {
     m_AIMovement   = GetComponent <AIMovement> ();
     m_NavMeshAgent = GetComponent <NavMeshAgent> ();
     m_AIAnimations = GetComponent <AIAnimations> ();
     m_AIHealth     = GetComponent <AIHealth> ();
     m_Animator     = GetComponent <Animator> ();
     m_AIBehaviours = GetComponent <AIBehaviours> ();
     m_Class        = GetComponent <Class> ();
     m_AIShooting   = GetComponent <AIShooting> ();
 }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     m_Collider           = GetComponent <Collider> ();
     m_NavMeshAgent       = GetComponent <NavMeshAgent> ();
     m_AIAnimations       = GetComponent <AIAnimations> ();
     m_AIMovement         = GetComponent <AIMovement> ();
     m_AIHealth           = GetComponent <AIHealth> ();
     m_Animator           = GetComponent <Animator> ();
     m_AIHealth.deathTime = deathTime;
     ActivateAI();
 }
Exemplo n.º 12
0
    void Melee()
    {
        RaycastHit2D rayHit = Physics2D.Raycast(transform.position, rayDir * 2f);

        if (rayHit.collider == null)
        {
            return;
        }

        if (rayHit.collider.tag == "Enemy")
        {
            AIHealth aiHealth = rayHit.collider.GetComponent <AIHealth>();
            aiHealth.Damage(curWeaponData.damageAmount);
        }
    }
Exemplo n.º 13
0
    protected virtual void OnTriggerEnter(Collider aCollider)
    {
        if (aCollider.gameObject.GetComponent <Bobble>() != null)
        {
            Bobble bobble = aCollider.gameObject.GetComponent <Bobble>();

            bobble.ApplyImpulse(transform.forward);
        }

        if (aCollider.gameObject.GetComponent <AIHealth>() != null)
        {
            AIHealth ai = aCollider.gameObject.GetComponent <AIHealth>();

            ai.TakeDamage(1, sourceObject.transform);

            Destroy(this.gameObject);
        }
    }
Exemplo n.º 14
0
    void OnEnable()
    {
        agent       = GetComponent <UnityEngine.AI.NavMeshAgent>();
        animator    = GetComponent <Animator>();
        AIHealth    = GetComponent <AIHealth>();
        AISensor    = GetComponentInChildren <AISensor>();
        AIRender    = GetComponent <AIRender>();
        AITransform = transform;

        targetPlayer = null;

        currentState = FSMState.Dead;

        agent.enabled = false;

        if (autoInit)
        {
            Born();
        }
    }
Exemplo n.º 15
0
    public void Explode()
    {
        GameObject eplxosionSFXClone = Instantiate(explosionEffect, explosionSpawnPoint.position, transform.rotation);

        Collider[] _colliders = Physics.OverlapSphere(transform.position, radius);
        {
            foreach (var nearbyObject in _colliders)
            {
                Prop      prop = nearbyObject.GetComponent <Prop>();
                Rigidbody rb   = nearbyObject.GetComponent <Rigidbody>();


                if (rb)
                {
                    rb.AddExplosionForce(force, transform.position, radius);
                }

                if (prop)
                {
                    prop.GetDamage(damage);
                }

                AIHealth aiHealth = nearbyObject.GetComponent <AIHealth>();
                if (aiHealth)
                {
                    aiHealth.TakeDamage(damage * 2, transform.position - aiHealth.transform.position, force);
                }

                InnocentHealth innocentHealth = nearbyObject.GetComponent <InnocentHealth>();
                if (innocentHealth)
                {
                    innocentHealth.TakeDamage(damage * 4, transform.position - innocentHealth.transform.position, force);
                }
            }
            GameEvents.events.CallExplosionSound();
            Destroy(eplxosionSFXClone, 2.2f);
            Destroy(gameObject, 2.2f);
        }
    }
Exemplo n.º 16
0
 private void Awake()
 {
     _sockets  = GetComponent <MeshSockets>();
     _weaponIK = GetComponent <WeaponIK>();
     _health   = GetComponent <AIHealth>();
 }
 // Use this for initialization
 void Awake()
 {
     aiShooting   = GetComponent <Complete.PlayerShooting>();
     navMeshAgent = GetComponentInChildren <UnityEngine.AI.NavMeshAgent>();
     aiHealth     = GetComponent <AIHealth>();
 }
Exemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        characterController = GetComponent<CharacterController>();

        aiHealthScript = GetComponent<AIHealth>();

        lastTimeShot = Time.time;

        mAI_MODE = AI_MODE.HARD;
        setAIMODE();
    }
 void Awake()
 {
     _aiHealth = GetComponentInParent <AIHealth>();
     _player   = FindObjectOfType <PlayerController>().transform;
 }
        public void Shoot()
        {
            // Reset the timer.
            timer = 0f;

            // Play the gun shot audioclip.
            gunAudio.Play();

            // Enable the lights.
            gunLight.enabled  = true;
            faceLight.enabled = true;

            // Stop the particles from playing if they were, then start the particles.
            gunParticles.Stop();
            gunParticles.Play();

            // Enable the line renderer and set it's first position to be the end of the gun.
            gunLine.enabled = true;
            gunLine.SetPosition(0, transform.position);

            // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
            shootRay.origin    = transform.position;
            shootRay.direction = transform.forward;
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.SphereCast(shootRay, 1f, out shootHit, range, shootableMask))
            {
                AIHealth enemyHealth = shootHit.collider.GetComponent <AIHealth>();
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    //  shootHit.rigidbody.constraints &= RigidbodyConstraints.FreezeAll;

                    if (shootHit.rigidbody != null)
                    {
                    }

                    if (enemyHealth.currentHealth <= 0)
                    {
                        shootHit.rigidbody.isKinematic = true;
                        Animator        animator       = shootHit.transform.gameObject.GetComponent <Animator>();
                        CapsuleCollider capsulCollider = shootHit.transform.gameObject.GetComponent <CapsuleCollider>();
                        Raggdoll        ragdoll        = shootHit.transform.gameObject.GetComponent <Raggdoll>();

                        if (animator != null && capsulCollider != null && capsulCollider.enabled == true)
                        {
                            ragdoll.enabledParts();
                            // capsulCollider.enabled = false;
                            StartCoroutine(waitFrame(animator, ragdoll, capsulCollider));
                        }
                    }
                }

                // Set the second position of the line renderer to the point the raycast hit.
                gunLine.SetPosition(1, shootHit.point);
            }
            // If the raycast didn't hit anything on the shootable layer...
            else
            {
                // ... set the second position of the line renderer to the fullest extent of the gun's range.
                gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
            }
        }
Exemplo n.º 21
0
        private static GameObject CreateAI(AIProperties properties)
        {
            // Instantiate AI object
            GameObject ai = GameObject.Instantiate(properties.GetModel(), Vector3.zero, Quaternion.identity);

            // Set tag and layer
            ai.name = properties.GetName();
            ai.tag  = TNC.AI;
            switch (properties.GetAIType())
            {
            case AIProperties.AIType.AgainstAll:
                ai.layer = LayerMask.NameToLayer(LNC.AI);
                break;

            case AIProperties.AIType.Friendly:
                ai.layer = LayerMask.NameToLayer(LNC.AI_FRIENDLY);
                break;

            case AIProperties.AIType.Enemy:
                ai.layer = LayerMask.NameToLayer(LNC.AI_ENEMY);
                break;
            }

            // Set components
            Animator animator = ai.GetComponent <Animator>();

            if (animator == null)
            {
                animator = ai.AddComponent <Animator>();
            }
            if (properties.GetController() != null)
            {
                animator.runtimeAnimatorController = properties.GetController();
            }

            AIController controller = ai.GetComponent <AIController>();

            if (controller == null)
            {
                controller = ai.AddComponent <AIController>();
            }

            AIHealth health = ai.GetComponent <AIHealth>();

            if (health == null)
            {
                health = ai.AddComponent <AIHealth>();
            }

            AIFieldOfView fieldOfView = ai.GetComponent <AIFieldOfView>();

            if (fieldOfView == null)
            {
                fieldOfView = ai.AddComponent <AIFieldOfView>();
            }

            AIAttackSystem attackSystem = ai.GetComponent <AIAttackSystem>();

            if (attackSystem == null)
            {
                attackSystem = ai.AddComponent <AIAttackSystem>();
            }

            AIReloadSystem reloadSystem = ai.GetComponent <AIReloadSystem>();

            if (reloadSystem == null)
            {
                reloadSystem = ai.AddComponent <AIReloadSystem>();
            }

            AIAnimatorHandler animatorHandler = ai.GetComponent <AIAnimatorHandler>();

            if (animatorHandler == null)
            {
                animatorHandler = ai.AddComponent <AIAnimatorHandler>();
            }

            CharacterRagdollSystem ragdollSystem = ai.GetComponent <CharacterRagdollSystem>();

            if (ragdollSystem == null)
            {
                ragdollSystem = ai.AddComponent <CharacterRagdollSystem>();
            }

            NavMeshAgent navMeshAgent = ai.GetComponent <NavMeshAgent>();

            if (navMeshAgent == null)
            {
                navMeshAgent = ai.AddComponent <NavMeshAgent>();
            }

            CapsuleCollider capsuleCollider = ai.GetComponent <CapsuleCollider>();

            if (capsuleCollider == null)
            {
                capsuleCollider = ai.AddComponent <CapsuleCollider>();
            }

            AudioSource audioSource = ai.GetComponent <AudioSource>();

            if (audioSource == null)
            {
                audioSource = ai.AddComponent <AudioSource>();
            }

            // Set component positions
            UEditorInternal.MoveComponentBottom <Animator>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIController>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIHealth>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIFieldOfView>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAttackSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIReloadSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAnimatorHandler>(ai.transform);
            UEditorInternal.MoveComponentBottom <CharacterRagdollSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <NavMeshAgent>(ai.transform);
            UEditorInternal.MoveComponentBottom <CapsuleCollider>(ai.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(ai.transform);

            // Set properties settings
            fieldOfView.SetTargetMask(properties.GetTargets());
            fieldOfView.SetObstacleMask(properties.GetObstacles());

            return(ai);
        }