Пример #1
0
    private CircleCollider2D QuakeCollider;                                                                                                             //variabel för att kunna komma åt collidern på objektet
    // Start is called before the first frame update
    void Start()
    {
        QuakeCollider = GetComponent <CircleCollider2D>();                                                                                              //tar den collidern vi vill göra saker med

        if (ShakeBehaviour.isShaking == false)                                                                                                          //ser till så att kameran inte redan skakar
        {
            ShakeBehaviour.Shake(ShakeDuration, ShakeMagnitude);                                                                                        //startar skaka skärmen med längden och styrkan som sätts i unity
        }
        EventManager.TriggerEvent("Earthquake");
        Instantiate(Cracks, new Vector3(transform.position.x, transform.position.y), Quaternion.identity);
    }
Пример #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        DamageDealer damageDealer = col.gameObject.GetComponent <DamageDealer>();

        if (damageDealer != null)
        {
            //Debug.Log(damageType.name + " hit: " + damageDealer.damageType.name);
            if (col.CompareTag("Shield") && gameObject.CompareTag("Bullet"))
            {
                var particle = col.GetComponentInChildren <ParticleSystem>();
                if (particle != null)
                {
                    particle.transform.position = gameObject.transform.position;
                    particle.Play();
                }

                Destroy(gameObject);
                return;
            }

            if (damageDealer.damageType.TakesDamageFrom.Contains(damageType))
            {
                col.gameObject.GetComponent <Stats>().DealDamage(DamageAmount.Value);

                if (!gameObject.CompareTag("Alien"))
                {
                    if (damageType.name == "Enemy")
                    {
                        ShakeBehaviour.Shake();
                    }

                    if (!gameObject.CompareTag("Fireball"))
                    {
                        Destroy(gameObject);
                    }
                }
            }
        }
    }
Пример #3
0
 // Start is called before the first frame update
 void Start()
 {
     ShakeBehaviour.Shake();
 }
 //Shake method
 void ShakeCamera()
 {
     StartCoroutine(CameraShake.Shake(_shakeDuration, _shakeMagnitude));
     _shake = false;
 }
Пример #5
0
    void SwitchState(PlayerState nextState)
    {
        switch (nextState)
        {
        case PlayerState.GROUNDED:
            hitstun = false;
            RefreshAbilities();

            if (!accelerating || currentState == PlayerState.FASTFALLING)
            {
                hspeed = normalHSpeed;
            }
            else
            {
                accelerating = true;
            }
            transform.position = new Vector3(transform.position.x, groundHeight, transform.position.z);
            renderer.sprite    = normalSprite;
            score.EndCombo();

            break;

        case PlayerState.RISING:         //jump
            if (currentState != PlayerState.DASHING)
            {
                hspeed       = jumpHSpeed;
                accelerating = true;
            }
            hasJump = false;

            break;

        case PlayerState.FALLING:         //fall
            StartFalling();
            break;

        case PlayerState.FASTFALLING:         //fastFall
            AudioSource.PlayClipAtPoint(fallSFX, Camera.main.transform.position);
            StartFastFalling();
            hspeed = fallHSpeed;
            break;

        case PlayerState.DASHING:
            Dash();
            AudioSource.PlayClipAtPoint(dashSFX, Camera.main.transform.position);
            if (currentState != PlayerState.GROUNDED)
            {
                hasDash = false;
            }
            break;

        case PlayerState.HIT:
            cameraShake.Shake(damageShakeConfig.pos, damageShakeConfig.time, damageShakeConfig.delay);
            AudioSource.PlayClipAtPoint(hitSFX, Camera.main.transform.position, 0.6f);
            DecreaseHealth(1);
            recoiling = true;
            hitstun   = true;

            targetX      = initialX - hitHKnockback;
            normalHSpeed = startingHSpeed;

            JumpTo(transform.position.y + hitKnockbackHeight, hitKnockbackDuration);
            nextState = PlayerState.RISING;
            break;

        default:
            break;
        }

        previousState = currentState;
        currentState  = nextState;
    }