예제 #1
0
 private void Jump()
 {
     if (_App.SoundManager)
     {
         _App.SoundManager.Play(_sfx.Get("Jump").audio);
     }
     RB.velocity = Vector2.zero;
     RB.AddForce(Vector2.up * _jumpForce);
     _jumpRequest = false;
     IsGrounded   = false;
 }
예제 #2
0
    protected void Update()
    {
        if (_targetPosition == null)
        {
            RaycastHit2D hitResult = Physics2D.Raycast(transform.position + (_moveVector * _playerCheckOffset), _moveVector, _playerCheckSize, LayerMask.GetMask("Player"));
            if (hitResult)
            {
                var hit = Physics2D.Raycast(transform.position, (hitResult.point - (Vector2)transform.position),
                                            Vector2.Distance(transform.position, hitResult.point), LayerMask.GetMask("Ground"));
                if (hit)
                {
                    return;
                }

                _targetPosition = hitResult.transform;
                if (_App.SoundManager)
                {
                    _App.SoundManager.Play(_sfx.Get("Alerted").audio);
                }
                _currState = EnemyStates.Follow;
                AllowMovement();
            }
            else
            {
                _targetPosition = null;
                _currState      = EnemyStates.Patrol;
            }
        }
        else if (Vector2.Distance(transform.position, _targetPosition.position) >= _targetMaxDistance)
        {
            _targetPosition = null;
            _moveVector     = (UnityEngine.Random.Range(0, 2) == 0) ? Vector3.right : Vector3.left;
            _currState      = EnemyStates.Patrol;
        }

        if (_enemyStates[(int)_currState] != null)
        {
            _enemyStates[(int)_currState]();
        }
    }
예제 #3
0
    private void Explode()
    {
        if (_App.SoundManager)
        {
            _App.SoundManager.Play(_sfx.Get("explode").audio);
        }
        if (CameraController.instance)
        {
            CameraController.instance.ScreenShake();
        }

        List <GameObject> objectsInRange = new List <GameObject>();

        RaycastHit2D[] hitResult;

        for (int i = 0; i < _hitMask.Length; i++)
        {
            hitResult = Physics2D.CircleCastAll(transform.position, _explosionRadius, Vector2.up, _explosionRadius, _hitMask[i].value);
            for (int n = 0; n < hitResult.Length; n++)
            {
                if (!objectsInRange.Contains(hitResult[n].collider.gameObject))
                {
                    objectsInRange.Add(hitResult[n].collider.gameObject);
                }
            }
        }

        for (int i = 0; i < objectsInRange.Count; i++)
        {
            Vector2 knockBackDir = objectsInRange[i].transform.position - transform.position;

            Character player = objectsInRange[i].GetComponent <Character>();
            Enemy2    enemy  = objectsInRange[i].GetComponent <Enemy2>();

            if (objectsInRange[i].GetComponent <Character>())
            {
                player.TakeDamage(_damage, knockBackDir, _explosionForce);
            }
            else if (objectsInRange[i].GetComponent <Enemy2>())
            {
                enemy.TakeDamage(_damage, knockBackDir, _explosionForce);
            }
        }

        StartCoroutine("DestroyObject");
    }
예제 #4
0
    protected void OnCollisionEnter2D(Collision2D coll)
    {
        Enemy2 enemy = coll.transform.GetComponent <Enemy2>();

        if (enemy)
        {
            enemy.TakeDamage(_damage, transform.right, enemy.KnockBackForce);
        }

        if (coll.gameObject.layer == LayerMask.NameToLayer("Ground"))
        {
            if (_App.SoundManager)
            {
                _App.SoundManager.Play(_sfx.Get("Impact").audio);
            }
        }

        Destroy(gameObject);
    }
예제 #5
0
    public void OnTriggerStay2D(Collider2D coll)
    {
        if (_pickupTrigger && _player)
        {
            if (_player.PickupBomb(BombsQtt))
            {
                if (_App.SoundManager)
                {
                    _App.SoundManager.Play(_sfx.Get("Collected").audio);
                }
                _animator.SetTrigger("Destroy");
                Destroy(gameObject, .3f);

                _pickupTrigger = false;
            }
            _player = null;
        }
        else
        {
            _player = coll.GetComponent <Character>();
        }
    }
예제 #6
0
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        script = (SFXDictionary)fieldInfo.GetValue(prop.serializedObject.targetObject);

        maxWindowSize = minWindowSize * (script.Count + 1);

        // Calculate rects
        var foldoutRect  = new Rect(pos.x, pos.y, (pos.width * .4f), minWindowSize);
        var newBtnRect   = new Rect(foldoutRect.x + foldoutRect.width, pos.y, (pos.width * .3f), minWindowSize);
        var clearBtnRect = new Rect(newBtnRect.x + newBtnRect.width, pos.y, (pos.width * .3f), minWindowSize);

        EditorGUI.BeginProperty(pos, label, prop);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        if ((foldoutState = EditorGUI.Foldout(foldoutRect, foldoutState, label)))
        {
            maxWindowSize += minWindowSize;
            var removeBtnRect = new Rect(pos.x, pos.y, (pos.width * .1f), minWindowSize);
            var sfxRect       = new Rect(removeBtnRect.x + removeBtnRect.width, pos.y, (pos.width * .9f), minWindowSize);
            for (int i = 0; i < script.Count; i++)
            {
                removeBtnRect.y = pos.y + minWindowSize * (i + 1);
                sfxRect.y       = pos.y + minWindowSize * (i + 1);
                if (GUI.Button(removeBtnRect, "-"))
                {
                    if (script.Get(i).audio != null)
                    {
                        if (EditorUtility.DisplayDialog("WARNING!", "Are your sure you want to remove this item?", "Yes", "No"))
                        {
                            script.Remove(i);
                        }
                    }
                    else
                    {
                        script.Remove(i);
                    }
                }
                else
                {
                    SerializedProperty value = prop.FindPropertyRelative("library").GetArrayElementAtIndex(i);
                    EditorGUI.PropertyField(sfxRect, value, GUIContent.none);
                }
            }
        }
        if (GUI.Button(newBtnRect, "Add"))
        {
            script.Add();
            foldoutState = true;
        }
        if (GUI.Button(clearBtnRect, "Clear"))
        {
            if (script.Count != 0)
            {
                if (EditorUtility.DisplayDialog("WARNING!", "Are your sure you want to remove this item?", "Yes", "No"))
                {
                    script.Clear();
                    foldoutState = false;
                }
            }
            else
            {
                script.Clear();
            }
        }
        // Set indent back to what it was
        EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty();
    }