Beispiel #1
0
    IEnumerator moveBullet(Vector3 hitPoint)
    {
        currentTrail  = Instantiate(sonarBullet, turretEndPosition.transform.position, Quaternion.identity);
        bMovingBullet = true;

        currentTrail.transform.LookAt(hitPoint);
        Vector3 startPos = turretEndPosition.transform.position + currentTrail.transform.forward * 2.0f;

        float distance      = Vector3.Distance(startPos, hitPoint);
        float timerVariable = (distance / 100.0f) * shotSpeedMultiplier;

        float t = 0.0f;

        while (t < timerVariable)
        {
            t += Time.deltaTime;
            currentTrail.transform.position = Vector3.Lerp(startPos, hitPoint, t / timerVariable);
            yield return(null);
        }

        if (currentTrail)
        {
            Collider[] hitColliders = Physics.OverlapSphere(currentTrail.transform.position, damageRadius);

            int i = 0;
            while (i < hitColliders.Length)
            {
                //damage players with mDamage
                if (hitColliders[i].gameObject.CompareTag("PlayerTrigger"))
                {
                    playerHealth = hitColliders[i].transform.parent.transform.parent.GetComponent <SCR_PlayerHealth>();
                    if (playerHealth)
                    {
                        playerHealth.DamagePlayer(damagePerShot);
                        //stun code
                        playerInputScr = playerHealth.gameObject.GetComponent <SCR_PlayerInput>();
                        StartCoroutine(playerInputScr.SlowPlayer(stunSpeed, stunTime));
                    }
                }

                i++;
            }

            Destroy(currentTrail);
            bMovingBullet = false;
        }
        bHitPointActive = true;
        hitTrail        = Instantiate(sonarHit, hitPoint, Quaternion.identity);
        hitTrail.transform.LookAt(turretEndPosition.transform.position);
        if (hitTrail)
        {
            Destroy(hitTrail, 0.3f);
            bHitPointActive = false;
        }
    }
 public override void SetPlayerParent(GameObject mPlayer)
 {
     playerHealthSCR = mPlayer.GetComponent <SCR_PlayerHealth>();
 }