Пример #1
0
    void FixedUpdate()
    {
        WobbleTime += Time.deltaTime * WobbleSpeed;
        Vector2 Wobble = new Vector2(Mathf.Sin(WobbleTime) * WobbleAmount / 8 * Mathf.PI, Mathf.Sin(WobbleTime) * WobbleAmount / 2 * Mathf.PI);

        Vector2 TargetPos2D = Target.position;
        Vector2 MoveDir     = rb.position - TargetPos2D;

        MoveDir.Normalize();

        MoveDir += Wobble;
        rb.MovePosition(rb.position - MoveDir * MoveSpeed * Time.deltaTime);


        if (bar.BarSize <= 0 || Health < -15f)
        {
            GameObject Effect = Instantiate(DeathExplosion, transform.position, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)));
            Destroy(Effect, 2f);
            controller.EnemyDeathCouter();
            Player.GainEnergy();
            Destroy(gameObject);
        }
    }