Beispiel #1
0
    private void Update()
    {
        try
        {
            if (goingToHit != null)
            {
                hitSound.Play(this.transform);
                goingToHit?.ReceiveDamage(damageAmount);
                Die();
                return;
            }

            RaycastHit2D hit = Physics2D.Raycast(this.transform.position, direction, speed * Time.deltaTime, collisionLayers);
            if (hit.collider != null)
            {
                this.transform.position = hit.point;
                this.goingToHit         = hit.collider.GetComponent <IDamage>();
            }
            else
            {
                this.transform.Translate(direction * speed * Time.deltaTime, Space.World);
            }
            if (currentTimeAlive >= maxTimeAlive)
            {
                Die();
            }
            else
            {
                currentTimeAlive += Time.deltaTime;
            }
        }
        catch
        {
            Die();
        }
    }