Exemplo n.º 1
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            CompleteProject.EnemyHealth enemyHealth = shootHit.collider.GetComponent <CompleteProject.EnemyHealth> ();
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }

        currentAmmo--;

        ammoText.text = "Ammo : " + currentAmmo.ToString();
    }
Exemplo n.º 2
0
    private void OnWizardCreate()
    {
        GameObject[] emenyPrefabs = Selection.gameObjects;


        int count = 0;

        EditorUtility.DisplayProgressBar("进度", count + "/" + emenyPrefabs.Length + "正在修改中!", 0);

        foreach (GameObject go in emenyPrefabs)
        {
            count++;
            CompleteProject.EnemyHealth hp = go.GetComponent <CompleteProject.EnemyHealth>();
            Undo.RecordObject(hp, "changHealthAndSpped");
            hp.startingHealth += changeStartHealthValue;
            hp.sinkSpeed      += sinkSpeedValue;

            EditorUtility.DisplayProgressBar("进度", count + "/" + emenyPrefabs.Length + "正在修改中!", (float)count / (float)emenyPrefabs.Length);
        }
        //可做延时处理
        EditorUtility.ClearProgressBar();

        ShowNotification(new GUIContent(Selection.gameObjects.Length + "个游戏物体的值被修改了"));

        Debug.Log("Click");
    }
Exemplo n.º 3
0
 void Awake()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     playerHealth = player.GetComponent <PlayerHealth> ();
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent <Animator> ();
 }
Exemplo n.º 4
0
        PlayerHealth playerHealth; // Reference to the player's health.

        #endregion Fields

        #region Methods

        void Awake()
        {
            // Set up the references.
            player = GameObject.FindGameObjectWithTag ("Player").transform;
            playerHealth = player.GetComponent <PlayerHealth> ();
            enemyHealth = GetComponent <EnemyHealth> ();
            nav = GetComponent <NavMeshAgent> ();
        }
Exemplo n.º 5
0
 void Awake()
 {
     // Setting up the references.
     player = GameObject.FindGameObjectWithTag ("Player");
     playerHealth = player.GetComponent <PlayerHealth> ();
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent <Animator> ();
 }
Exemplo n.º 6
0
        PlayerHealth playerHealth; // Reference to the player's health.

        #endregion Fields

        #region Methods

        void Awake()
        {
            // Set up the references.
            player = GameObject.FindGameObjectWithTag ("Player").transform;
            playerHealth = player.GetComponent <PlayerHealth> ();
            enemyHealth = GetComponent <EnemyHealth> ();
            nav = GetComponent <NavMeshAgent> ();
            nav.acceleration = Random.Range (0.5f, 1.0f);
            //nav.acceleration = 0.5f;
            //nav.speed = Random.Range (5.0f, 10.0f);
        }
Exemplo n.º 7
0
 void Awake()
 {
     // Setting up the references.
     player = GameObject.FindGameObjectWithTag("Player");
     playerHealth = player.GetComponent<PlayerHealth>();
     enemyHealth = GetComponent<EnemyHealth>();
     anim = GetComponent<Animator>();
     enemySight = GetComponent<EnemySight>();
     lastPlayerSighting = GameObject.FindGameObjectWithTag("GameController").GetComponent<LastPlayerSighting>();
     playerInRange = false;
 }
Exemplo n.º 8
0
        private int wayPointIndex; // A counter for the way point array.

        #endregion Fields

        #region Methods

        void Awake()
        {
            // Setting up the references.
            enemySight = GetComponent<EnemySight>();
            nav = GetComponent<NavMeshAgent>();
            player = GameObject.FindGameObjectWithTag("Player").transform;
            playerHealth = player.GetComponent<PlayerHealth>();
            enemyHealth = GetComponent<EnemyHealth>();
            lastPlayerSighting = GameObject.FindGameObjectWithTag("GameController").GetComponent<LastPlayerSighting>();
            wayPointIndex = 0;
            onHpRegen = false;
        }
Exemplo n.º 9
0
    // 检查对话框create按钮的点击,按钮名更改但是检查的函数名还是固定为OnWizardCreate
    private void OnWizardCreate()
    {
        GameObject[] gos = Selection.gameObjects;
        foreach (GameObject go in gos)
        {
            CompleteProject.EnemyHealth hp = go.GetComponent <CompleteProject.EnemyHealth>();
            Undo.RecordObject(hp, "change health and speed");  //记录对象,可进行撤销操作
            hp.startingHealth += addHealth;
            hp.sinkSpeed      += addSpeed;
        }
        ShowNotification(new GUIContent("有" + gos.Length + "个游戏物体值被改变"));

        EditorPrefs.SetInt("xx", addHealth);
        EditorPrefs.SetInt("yy", addSpeed);
    }
Exemplo n.º 10
0
    protected override bool OnCheck()
    {
        if (currentHealth.value < 100)
        {
            if (healthBlock != null)
            {
                if (currentHealth.value < dangerHealth.value)
                {
                    return(true);
                }

                Vector3 healthDirection = (healthBlock.value.pos - ownerAgent.transform.position);
                if (healthDirection.magnitude < healthPickupDistance.value)
                {
                    RaycastHit[] hits = Physics.BoxCastAll(ownerAgent.transform.position, Vector3.one * 3, healthDirection.normalized);

                    int enemyInTheWay = 0;

                    for (int i = 0; i < hits.Length; i++)
                    {
                        CompleteProject.EnemyHealth enemyHealth = hits[i].transform.GetComponent <CompleteProject.EnemyHealth>();

                        if (enemyHealth)
                        {
                            enemyInTheWay++;
                        }
                    }

                    Debug.Log("Enemy In The Way:" + enemyInTheWay);

                    if (currentHealth.value > (enemyInTheWay + 1) * 10)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// 固定函数名:对应现实向导中的第一个按钮 —— 确认修改血量
    /// </summary>
    void OnWizardCreate()
    {
        EditorUtility.DisplayProgressBar("修改进度", "0/" + Selection.gameObjects.Length + "完成修改", 1);                                               //进度条
        int count = 0;                                                                                                                           //计数

        foreach (var gameObject in Selection.gameObjects)                                                                                        //遍历选中的物体
        {
            CompleteProject.EnemyHealth health = gameObject.GetComponent <CompleteProject.EnemyHealth>();                                        //获取其身上脚本组件
            Undo.RecordObject(health, "Change health");                                                                                          //记录变量 health 之后做的更改
            health.startingHealth += AddHp;                                                                                                      //自增 设置的值   //需要修改其他属性,自己往下写
            count++;                                                                                                                             //计数自增1
            EditorUtility.DisplayProgressBar("修改进度", count + "/" + Selection.gameObjects.Length + "完成修改", count / Selection.gameObjects.Length); //进度条
        }

        EditorUtility.ClearProgressBar(); //清除进度条(只有调用此方法,进度条才会删除)
    }
Exemplo n.º 12
0
    protected override void OnExecute()
    {
        base.OnExecute();

        FindEnemy();

        if (target.value != null)
        {
            CompleteProject.EnemyHealth enemyHealth = target.value.GetComponent <CompleteProject.EnemyHealth>();
            if (enemyHealth.currentHealth <= 0)
            {
                target.value = null;
            }
        }

        EndAction(true);
    }
    //检测create按钮的点击
    void OnWizardCreate()
    {
        GameObject[] enemyPrefabs = Selection.gameObjects;
        EditorUtility.DisplayProgressBar("进度", "0/" + enemyPrefabs.Length + " 完成修改值", 0);
        int count = 0;

        foreach (GameObject go in enemyPrefabs)
        {
            CompleteProject.EnemyHealth hp = go.GetComponent <CompleteProject.EnemyHealth>();
            Undo.RecordObject(hp, "change health and speed");
            hp.startingHealth += changeStartHealthValue;
            hp.sinkSpeed      += changeSinkSpeedValue;
            count++;
            EditorUtility.DisplayProgressBar("进度", count + "/" + enemyPrefabs.Length + " 完成修改值", (float)count / enemyPrefabs.Length);
        }
        EditorUtility.ClearProgressBar();
        ShowNotification(new GUIContent(Selection.gameObjects.Length + "个游戏物体的值被修改了"));
    }
Exemplo n.º 14
0
    int CheckEnemyCount(Vector3 position, float radius)
    {
        Collider[] cols = Physics.OverlapSphere(position, radius);

        List <CompleteProject.EnemyHealth> enemies = new List <CompleteProject.EnemyHealth>();

        for (int i = 0; i < cols.Length; i++)
        {
            CompleteProject.EnemyHealth enemyHealth = cols[i].GetComponent <CompleteProject.EnemyHealth>();

            if (enemyHealth && enemyHealth.currentHealth > 0 && !enemies.Contains(enemyHealth))
            {
                enemies.Add(enemyHealth);
            }
        }

        return(enemies.Count);
    }
Exemplo n.º 15
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;
        // Bit shift the index of the layer (8) to get a bit mask
        int layerMask = 1 << 8;

        // This would cast rays only against colliders in layer 8.
        // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
        layerMask = ~layerMask;

        if (Physics.Raycast(shootRay, out shootHit, range, layerMask))
        {
            CompleteProject.EnemyHealth enemyHealth = shootHit.collider.GetComponent <CompleteProject.EnemyHealth> ();
            ShatterOnCollision          shatter     = shootHit.collider.GetComponent <ShatterOnCollision>();

            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            else if (shatter != null)
            {
                shatter.Action();
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Exemplo n.º 16
0
    public void AirstrikeDamage(Vector3 detonationPoint)
    {
        //  Dispatch event to flash
        EventManager.Instance.SendEvent("OnAirstrikeCollide");

        //  Get colliders in overlap sphere.
        Collider[] hitColliders = Physics.OverlapSphere(detonationPoint, blastRadius, shootableMask);

        //  Iterate through colliders
        foreach (Collider hitCollider in hitColliders)
        {
            //  get enemy health component.
            CompleteProject.EnemyHealth enemyHealth = hitCollider.gameObject.GetComponentInChildren <CompleteProject.EnemyHealth>();
            if (enemyHealth != null)
            {
                if (Vector3.Distance(detonationPoint, hitCollider.transform.position) < blastRadius)
                {
                    //  find distance.
                    float distance = Vector3.Distance(detonationPoint, hitCollider.transform.position);

                    //  find damage.
                    int damage = -Mathf.RoundToInt(Mathf.Pow(distance / blastRadius, 2)) + maxDamage;

                    //  raycast to find the point where the blast hits.
                    RaycastHit damageHit;
                    Physics.Raycast(detonationPoint, (hitCollider.transform.position - detonationPoint), out damageHit);
                    Vector3 hitPoint = damageHit.point;

                    //Debug.DrawRay(detonationPoint, hitCollider.transform.position - detonationPoint, Color.red, Mathf.Infinity);

                    Log.Debug("AirStrike", "damage: {0}, hitPoint: {1}, distance: {2}", damage, hitPoint, distance);

                    //  deal damage.
                    enemyHealth.TakeDamage(damage, hitPoint);
                }
            }
        }

        isDetonated = true;

        Destroy(gameObject);
    }
Exemplo n.º 17
0
    //按钮点击 之后触发的事件
    private void OnWizardCreate()
    {
        //objects 是场景中 这个包含预制体
        GameObject[] enemyP = Selection.gameObjects;
        //进度条
        EditorUtility.DisplayProgressBar("进度", "0/" + enemyP.Length + "完成修改值", 0);
        int count = 0;

        for (int i = 0; i < enemyP.Length; i++)
        {
            CompleteProject.EnemyHealth e = enemyP[i].GetComponent <CompleteProject.EnemyHealth>();
            //编辑器记录下可以撤回 放在改变之前
            Undo.RecordObject(e, "change health and speed");
            e.startingHealth += 10;
            e.sinkSpeed      += 1;
            count++;
            EditorUtility.DisplayProgressBar("进度", "0/" + enemyP.Length + "完成修改值", (float)i / enemyP.Length);
        }
        //清空进度条
        //EditorUtility.ClearProgressBar();
        ShowNotification(new GUIContent($"{ Selection.gameObjects.Length}个游戏的值被修改了"));
    }
Exemplo n.º 18
0
    //当默认按钮被点击时
    void OnWizardCreate()
    {
        Debug.Log("click");
        GameObject[] enmy = Selection.gameObjects;
        EditorUtility.DisplayProgressBar("进度", "0/" + enmy.Length + "完成修改值", 0);
        int count = 0;

        foreach (GameObject go in enmy)
        {
            CompleteProject.EnemyHealth hp = go.GetComponent <CompleteProject.EnemyHealth>();
            Undo.RecordObject(hp, "che xiao");//要在对象前调用,写入Unity进程,能撤销
            hp.startingHealth += changeHealthValue;
            hp.sinkSpeed      += changeSinkSpeedValue;
            count++;
            EditorUtility.DisplayProgressBar("进度", count + "/" + enmy.Length + "完成修改值", (float)count / enmy.Length);
        }
        EditorUtility.ClearProgressBar(); //清理进度条
        ShowNotification(new GUIContent(Selection.gameObjects.Length + "个敌人"));

        EditorPrefs.SetInt(changehealthValue, changeHealthValue);
        EditorPrefs.SetInt(changesinkSpeedValue, changeSinkSpeedValue);
    }
Exemplo n.º 19
0
        void Awake()
        {
            Enemy_s = Enemy_State.Idle; // 쉬는상태

            this_trs = this.transform;

            Attack = false;
            // Set up the references.
            player = GameObject.Find("Player").transform;
            playerHealth = player.GetComponent <PlayerHealth> ();
            enemyHealth = GetComponent <EnemyHealth> ();
            nav = GetComponent <NavMeshAgent> ();

            nav.autoBraking = true;
            nav.autoRepath = true;

            temp_Vector = this_trs.position;
            Move_cnt = 0;

            speed = nav.speed;
            switch (this.gameObject.name)
            {
                case "ZomBunny(Clone)":
                    Range = 6;
                    break;
                case "ZomBear(Clone)":
                    Range = 8;
                    break;
                case "Hellephant(Clone)":
                    Range = 10;
                    break;
                case "FirstAid(Clone)":
                    Range = 0;
                    break;

            }
        }
Exemplo n.º 20
0
        void CastShootRay(LineRenderer gunLine, Vector3 direction)
        {
            // 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.
            Ray shootRay = new Ray();                       // A ray from the gun end forwards.

            shootRay.origin    = transform.position;
            shootRay.direction = direction;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }
                LuaFunction.FireEvent("ShootEnemy", shootHit.collider.gameObject.GetInstanceID(), damagePerShot, shootHit.point);

                // 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
        UnityEngine.AI.NavMeshAgent nav; // Reference to the nav mesh agent.


        void Awake()
        {
            enemyHealth = GetComponent <EnemyHealth> ();
            nav         = GetComponent <UnityEngine.AI.NavMeshAgent> ();
        }
Exemplo n.º 22
0
        float timer;                                // Timer for counting up to the next attack.


        void Awake()
        {
            // Setting up the references.
            enemyHealth = GetComponent <EnemyHealth>();
            anim        = GetComponent <Animator> ();
        }
        public int Shoot(Vector3 origin, Vector3 direction, out Vector3 destination)
        {
            Debug.Log("Shooting");
            Debug.Log(origin);
            // 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, origin);
             */
            // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
            shootRay.origin    = origin;
            shootRay.direction = direction;
            //destination = origin;
            int score = 0;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                if (PlayerManager.instance.startGame)
                {
                    // Try and find an EnemyHealth script on the gameobject hit.
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    // If the EnemyHealth component exist...
                    if (enemyHealth != null)
                    {
                        // ... the enemy should take damage.
                        score = enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }
                    else
                    {
                        Debug.Log("No ennemy");
                    }
                }
                else
                {
                    VRStandardAssets.ShootingGallery.ShootingTarget shootingTarget = shootHit.collider.GetComponent <VRStandardAssets.ShootingGallery.ShootingTarget>();
                    // If the EnemyHealth component exist...
                    if (shootingTarget != null)
                    {
                        // ... the enemy should take damage.
                        if (vrGun != null && transform.parent.parent.GetComponent <NetworkShoot>().isLocalPlayer)
                        {
                            //shootingTarget.ImReady();
                            score = -1;
                        }
                        else
                        {
                            score = -2;
                            Debug.Log("Not local player");
                        }
                    }
                    else
                    {
                        Debug.Log("No ennemy");
                    }
                }


                // Set the second position of the line renderer to the point the raycast hit.
                //gunLine.SetPosition (1, shootHit.point);
                destination = shootHit.point;
            }
            // If the raycast didn't hit anything on the shootable layer...
            else
            {
                Debug.Log("Shooting fail");

                // ... set the second position of the line renderer to the fullest extent of the gun's range.
                destination = shootRay.origin + shootRay.direction * range;
            }
            return(score);
        }
        void Shoot()
        {
            shot++;
            //int shot = 0;
            timer = 0f;
            int randomclip = Random.Range(0, shotClips.Count);

            Debug.Log("OnTriggerEnter" + Time.time);
            float randomVol = Random.Range(0.3f, 0.8f);

            aSource.volume = randomVol;

            float randomPitch = Random.Range(1, 3);

            aSource.pitch = randomPitch;
            SingleShot();
            if (shot % 3 == 0)
            {
                for (int shot = 0; shot <= 2; shot++)
                {
                    Invoke("Shell", shot * 0.2f);
                }
            }

            /*if(shot < 4){ //how to check specific clip?
             *
             *  aSource.PlayOneShot(shotClips[randomclip]);
             *
             *  if(shot == 3){
             *      for(int shot = 0; shot <= 2; shot++)
             *          {
             *              aSource.PlayOneShot(shellClips[randomclip]);
             *              aSource.clip = shellClips[randomclip];
             *
             *          }
             *         Invoke("PauseSound", 3f);
             *       //need to pause animation
             *      //aSource.PlayDelayed(1f);
             *  }
             * } */

            /* for(int shot = 0; shot <= 2; shot++)
             * {
             *   Invoke("SingleShot", shot);
             * }
             * Invoke("PauseSound", 3f);*/
            // ignore mouse press until shells finished playing



            // 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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }

                // 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.º 25
0
 void Awake()
 {
     // Load boss' life based on the EnemyHealth script
     currentHealth = startingHealth;
     life          = GetComponent <EnemyHealth>();
 }
Exemplo n.º 26
0
        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;

            EnemyHealth enemyHealth = null;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }

                // 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);
            }

            Debug.Log("Tracking Shoot");
            RudderEvent rudderEvent = new RudderEventBuilder()
                                      .SetEventName("PlayerShooting_Shoot")
                                      .SetUserId("w240adxe7fseasn34m6u-4vpw1n7iac2jz9b135s7")
                                      .Build();
            RudderProperty rudderProperty = new RudderProperty();

            rudderProperty.AddProperty("category", "Shoot");
            rudderProperty.AddProperty("transform_position", transform.position.ToString());
            if (enemyHealth != null)
            {
                rudderProperty.AddProperty("enemy_health", enemyHealth.currentHealth.ToString());
            }
            rudderEvent.SetProperties(rudderProperty);
            rudderEvent.AddIntegrations(RudderIntegrationPlatform.ALL, false);
            rudderEvent.AddIntegrations(RudderIntegrationPlatform.GOOGLE_ANALYTICS, true);
            rudderEvent.AddIntegrations(RudderIntegrationPlatform.AMPLITUDE, true);
            CompleteProject.PlayerMovement.rudderInstance.Track(rudderEvent);
            // Dictionary<string, object> demoOptions = new Dictionary<string, object>() {
            //     {"category" , "Shoot" },
            //     {"transform_position" , transform.position.ToString()},
            //     {"rl_message_id" , rudderEvent.rl_message.rl_message_id}
            // };
            // if (enemyHealth != null)
            // {
            //     demoOptions.Add("enemy_health", enemyHealth.currentHealth);
            // }
            // Amplitude.Instance.logEvent("PlayerShooting_Shoot Direct", demoOptions);
        }
Exemplo n.º 27
0
    private void FindEnemy()
    {
        List <GameObject> enemies = new List <GameObject>();

        Collider[] cols = Physics.OverlapSphere(ownerAgent.transform.position, radius.value);
        Debug.DrawLine(ownerAgent.transform.position, ownerAgent.transform.position + ownerAgent.transform.forward * radius.value, Color.yellow);
        //Debug.Log(cols.Length);

        int   nearestEnemyIdx    = 0;
        float nearestSqrDistance = 10000;

        enemyCountInBombRange.value = 0;

        for (int i = 0; i < cols.Length; i++)
        {
            Vector3 ownerCenter  = ownerAgent.GetComponent <Collider>().bounds.center;
            Vector3 targetCenter = cols[i].bounds.center;

            Vector3 direction = (targetCenter - ownerCenter).normalized;

            RaycastHit hit;

            if (Physics.Raycast(ownerCenter, direction, out hit))
            {
                if (hit.collider != cols[i])
                {
                    continue;
                }
            }

            CompleteProject.EnemyHealth enemyHealth = cols[i].GetComponent <CompleteProject.EnemyHealth>();
            //Debug.Log("Find:" + cols[i].gameObject.name);

            if (enemyHealth && enemyHealth.currentHealth > 0)
            {
                //Debug.Log("Enemy:" + cols[i].gameObject.name);
                if (enemies.Contains(enemyHealth.gameObject))
                {
                    continue;
                }

                float sqrDistance = Vector3.SqrMagnitude(ownerAgent.transform.position - enemyHealth.transform.position);

                if (sqrDistance < 6 * 6)
                {
                    enemyCountInBombRange.value++;
                }

                if (sqrDistance < nearestSqrDistance)
                {
                    nearestSqrDistance = sqrDistance;
                    nearestEnemyIdx    = enemies.Count;
                }

                enemies.Add(enemyHealth.gameObject);
            }
        }

        if (enemies.Count > 0)
        {
            //Debug.Log("Find Enemy:" + enemies.Count);
            if (this.target.value == null)
            {
                this.enemies.value = enemies;
                this.target.value  = this.enemies.value[nearestEnemyIdx];
            }
        }
        else
        {
            this.target.value = null;
        }
    }
Exemplo n.º 28
0
        /* La función es la encargada realizar
         * el disparo del jugador, el cual se
         * encargda de emplear la trayectoria de
         * la bala con la función seno, y se
         * genera el daño por bala por medio de
         * la función coseno.
         */
        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;
            gunLineCenter.enabled = true;

            // 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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();

                //PARA GENERAR DAÑO ALEATORIO
                int danoPorBala = 30;                        //Inicializamos el valor de daño por cada bala en 30
                if (Application.loadedLevelName == "level2") //Si se encuentra en el nivel2 el daño por bala va a ser siempre 100
                {
                    damagePerShot = 100;                     //Toma el valor de 100
                }
                else                                         // si estamos en el nivel1
                                                             //Aplicamos la función cosenos para asignar daño por bala
                {
                    float funcionCos = Mathf.Cos(Random.Range(-Mathf.PI / 2, Mathf.PI / 2));
                    int   danoF      = (int)(funcionCos * 100); //Multiplixamos por 100 dado a que la función Coseno toma valores entre [0-1]
                    if (danoF <= danoPorBala)                   //Si es menor a 30 entonces asignamos el número aleatorio a daño por bala
                    {
                        damagePerShot = danoF;                  //se asigna el valor al la variable daño
                    }
                    else                                        //Si es  mayor a 30 asignamos 30 a daño por bala
                    {
                        damagePerShot = danoPorBala;
                    }
                }
                //Fin generar daño aleatorio

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }

                // Set the second position of the line renderer to the point the raycast hit.
                Vector3   dir              = (shootHit.point - transform.position).normalized;
                Vector3[] points           = new Vector3[lengthOfLineRenderer];      // se crea un arreglo de vectores de 3 dimensiones, donde se guardara cada vertice de la linea
                float     t                = Time.time;
                float     tamanoDivisiones = (shootHit.point - transform.position).magnitude / lengthOfLineRenderer;
                int       i                = 1;
                points [0] = transform.position;
                while (i < lengthOfLineRenderer)
                {
                    points[i] = new Vector3((i * tamanoDivisiones * dir.x) + transform.position.x,
                                            shootHit.point.y,
                                            (Mathf.Sin(i + t)) + (i * tamanoDivisiones * dir.z) + transform.position.z);
                    i++;
                }
                gunLine.SetPositions(points);                // crea una linea por todos los vertices guardados en el arreglo
            }
            // 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.º 29
0
        void Shoot()
        {
            if (!bulletExplosion)
            {
                // 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;


                // Perform the raycast against gameobjects on the shootable layer and if it hits something...
                if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
                {
                    // Try and find an EnemyHealth script on the gameobject hit.
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    // If the EnemyHealth component exist...
                    if (enemyHealth != null)
                    {
                        // ... the enemy should take damage.
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    // 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);
                }
            }
            else
            {
                // 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;
                shootRayBack.origin      = transform.position;
                shootRayBack.direction   = transform.forward * -1;
                shootRayLeft.origin      = transform.position;
                shootRayLeft.direction   = transform.right * -1;
                shootRayRight.origin     = transform.position;
                shootRayRight.direction  = transform.right;
                shootRay45.origin        = transform.position;
                shootRay45.direction     = (transform.forward + transform.right).normalized;
                shootRayneg45.origin     = transform.position;
                shootRayneg45.direction  = (transform.forward - transform.right).normalized;
                shootRay135.origin       = transform.position;
                shootRay135.direction    = -(transform.forward + transform.right).normalized;
                shootRayneg135.origin    = transform.position;
                shootRayneg135.direction = -(transform.forward - transform.right).normalized;

                if (Physics.Raycast(shootRayneg45, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRayneg45.origin + shootRayneg45.direction * range);
                }
                if (Physics.Raycast(shootRayneg135, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRayneg135.origin + shootRayneg135.direction * range);
                }
                if (Physics.Raycast(shootRay135, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRay135.origin + shootRay135.direction * range);
                }

                if (Physics.Raycast(shootRayBack, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRayBack.origin + shootRayBack.direction * range);
                }
                if (Physics.Raycast(shootRayLeft, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRayLeft.origin + shootRayLeft.direction * range);
                }
                if (Physics.Raycast(shootRayRight, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRayRight.origin + shootRayRight.direction * range);
                }
                if (Physics.Raycast(shootRay45, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRay45.origin + shootRay45.direction * range);
                }
                if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
                }
            }
        }
Exemplo n.º 30
0
        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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);

                    //当たるたびに経験値
                    if (GunType == 0)
                    {
                        if (GunLv.ARLV <= 10)
                        {
                            GunLv.AR += 3;
                        }
                    }
                    if (GunType == 1)
                    {
                        if (GunLv.LMGLV <= 10)
                        {
                            GunLv.LMG += 1;
                        }
                    }
                    if (GunType == 2)
                    {
                        if (GunLv.SGLV <= 10)
                        {
                            GunLv.SG += 3;
                        }
                    }
                    if (GunType == 3)
                    {
                        if (GunLv.SRLV <= 10)
                        {
                            GunLv.SR += 5;
                        }
                    }
                }

                // 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.º 31
0
        UnityEngine.AI.NavMeshAgent nav;               // Reference to the nav mesh agent.


        void Awake()
        {
            // Set up the references.
            enemyHealth = GetComponent <EnemyHealth> ();
            nav         = GetComponent <UnityEngine.AI.NavMeshAgent> ();
        }
Exemplo n.º 32
0
        void Shoot()
        {
            if (currentBullets <= 0)
            {
                return;
            }

            currentBullets--;
            ammoSlider.value = currentBullets;

            // 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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    enemyImage.enabled = true;
                    enemyImage.sprite  = enemyHealth.icon;
                    enemyHealthSlider.gameObject.SetActive(true);
                    enemyHealthSlider.value = enemyHealth.GetHealthPercentage();
                    StopCoroutine(ScheduleHideEnemyUI());
                    StartCoroutine(ScheduleHideEnemyUI());
                }
                else
                {
                    HideEnemyUI();
                }

                // 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);
            }
        }
        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;

            Vector3 finalPoint = new Vector3();

            finalPoint.Set(0, 0, 0);

            float currentRange = range;


            if (onPower)
            {
                // Perform the raycast against gameobjects on the shootable layer and if it hits something...
                while ((range > 0) && (Physics.SphereCast(shootRay.origin, 1f, shootRay.direction, out shootHit, currentRange, shootableMask)))
                {
                    //if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
                    // Try and find an EnemyHealth script on the gameobject hit.
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();

                    // If the EnemyHealth component exist...
                    if (enemyHealth != null)
                    {
                        // ... the enemy should take damage.
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }


                    // Set the second position of the line renderer to the point the raycast hit.
                    //gunLine.SetPosition (1, shootHit.point);
                    finalPoint = shootHit.point + shootHit.normal.normalized + shootRay.direction.normalized;
                    //gunLine.SetPosition (1, finalPoint);
                    currentRange   -= (finalPoint - shootRay.origin).magnitude;
                    shootRay.origin = finalPoint;
                    //gunLine.SetPosition (0, finalPoint);
                }
                gunLine.SetPosition(1, transform.position + shootRay.direction * range);
            }
            else
            {
                if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
                {
                    // Try and find an EnemyHealth script on the gameobject hit.
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();

                    // If the EnemyHealth component exist...
                    if (enemyHealth != null)
                    {
                        // ... the enemy should take damage.
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                    }

                    // Set the second position of the line renderer to the point the raycast hit.
                    gunLine.SetPosition(1, shootHit.point);
                }
                else
                {
                    gunLine.SetPosition(1, transform.position + shootRay.direction * range);
                }
            }
        }
Exemplo n.º 34
0
 void OnEnemyDied(EnemyHealth enemy) =>
 Instances.Remove(enemy);
Exemplo n.º 35
0
        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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null)
                {
                    // ... the enemy should take damage.
                    enemyHealth.TakeDamage(damagePerShot, shootHit.point);
                }

                // 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);
            }

            Dictionary <string, object> eventProperty = new TrackPropertyBuilder()
                                                        .SetCategory("PlayerShooting_Shoot")
                                                        .Build();

            eventProperty.Add("dummy_e_prop_1", "dummy_e_prop_1_value");
            eventProperty.Add("dummy_e_prop_2", "dummy_e_prop_2_value");
            eventProperty.Add("dummy_e_prop_3", "dummy_e_prop_3_value");
            eventProperty.Add("score", ScoreManager.score);

            Dictionary <string, object> userProperty = new Dictionary <string, object> ();

            userProperty.Add("dummy_prop_1", "dummp_prop_1_value");
            userProperty.Add("dummy_prop_2", "dummp_prop_2_value");

            RudderElement element = new RudderElementBuilder()
                                    .WithEventName("PlayerShooting_Shoot")
                                    .WithUserId("test_user_id_sayan_android")
                                    .WithEventProperties(eventProperty)
                                    .WithUserProperties(userProperty)
                                    .Build();

            element.integrations = new Dictionary <string, object>();
            element.integrations.Add("All", false);
            element.integrations.Add("AM", true);
            element.integrations.Add("GA", true);

            PlayerMovement.rudderClient.Track(element);
        }
Exemplo n.º 36
0
        void Start()
        {
            player = GameObject.FindGameObjectWithTag("Player").transform;
            playerHealth = player.GetComponent<PlayerHealth>();
            enemyHealth = GetComponent<EnemyHealth>();
            nav = GetComponent<NavMeshAgent>();

            isMoving = false;
            footStepsAudio = FMOD_StudioSystem.instance.GetEvent(audioPath);

            enemyManagers = GameObject.Find("/EnemyManager").GetComponents<EnemyManager>();
        }
Exemplo n.º 37
0
        void IceShoot()
        {
            // 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;

            // Perform the raycast against gameobjects on the shootable layer and if it hits something...
            if (Physics.Raycast(shootRay, out shootHit, range, attackableMask))
            {
                // Try and find an EnemyHealth script on the gameobject hit.
                EnemyHealth   enemyHealth   = shootHit.collider.GetComponent <EnemyHealth>();
                EnemyMovement enemyMovement = shootHit.collider.GetComponent <EnemyMovement>();

                // If the EnemyHealth component exist...
                if (enemyHealth != null && enemyMovement != null && !enemyMovement.frozen && !enemyMovement.slowed)
                {
                    // ... the enemy should take damage.
                    enemyHealth.Shot(damagePerAttack, shootHit.point);
                    enemyMovement.hitsUntilFrozen--;
                    enemyMovement.slowed = true;
                }

                if (enemyHealth != null && enemyMovement != null && !enemyMovement.frozen && enemyMovement.slowed)
                {
                    // ... the enemy should take damage.
                    enemyHealth.Shot(damagePerAttack, shootHit.point);
                    enemyMovement.hitsUntilFrozen--;
                }

                if (enemyHealth != null && enemyMovement != null && enemyMovement.frozen && enemyMovement.slowed)
                {
                    // ... the enemy should take damage.
                    enemyHealth.Shot(damagePerAttack, shootHit.point);
                }

                else if (enemyHealth == null && enemyMovement == null)
                {
                    //					enemyMovement.nav.speed = enemySpeed;
                    return;
                }

                // 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.º 38
0
        void Update()
        {
            if (!IsDeployed)
            {
                return;
            }

            timer += Time.deltaTime;

            if (timer >= timeBetweenBullets * effectsDisplayTime)
            {
                DisableEffects();
            }

            if (!target || target.IsDead)
            {
                SortedList <float, EnemyHealth> validTargets = new SortedList <float, EnemyHealth>();
                enemiesInRange.RemoveAll(o => o == null);
                foreach (EnemyHealth comp in enemiesInRange)
                {
                    Transform trans = comp.transform;
                    if (Vector3.Magnitude(transform.position - trans.position) > range * range || !CheckVisibility(trans))
                    {
                        continue;
                    }
                    float tangle = Mathf.Abs(Vector3.SignedAngle(transform.forward, trans.position - transform.position, Vector3.up));
                    if (!validTargets.ContainsKey(tangle))
                    {
                        validTargets.Add(tangle, comp);
                    }
                }
                if (validTargets.Count > 0)
                {
                    target = validTargets.Values[0];
                }
                else
                {
                    target = null;
                    return;
                }
            }
            if (Vector3.Magnitude(transform.position - target.transform.position) > range * range)
            {
                target = null;
                return;
            }

            Vector3 dirVector = target.transform.position - transform.position;

            dirVector.y = 0;

            Quaternion newRotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(dirVector, Vector3.up), Time.deltaTime * rotationSpeed);

            transform.rotation = newRotation;

            float angle = Mathf.Abs(Vector3.SignedAngle(transform.forward, dirVector, Vector3.up));

            if (angle < 10.0f && timer >= timeBetweenBullets && Time.timeScale != 0)
            {
                Shoot();
            }
        }