コード例 #1
0
 // Use this for initialization
 void Start()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
コード例 #2
0
 public void Damage(int playerHealth)
 {
     if (playerHealth != 0)
     {
         healthContainer.GetChild(playerHealth - 1).gameObject.GetComponent <Animator>().SetTrigger("Damage");
     }
     CameraShakerController.CameraShake();
     Debug.Log("PlayerHit");
 }
コード例 #3
0
    public void FixedTick()
    {
        if (_swingTime >= 0)
        {
            _swingTime += Time.deltaTime;

            float from = _currentBatPos == BatPosition.Left ? ANGLE_LEFT : ANGLE_RIGHT;
            float to   = _currentBatPos == BatPosition.Left ? ANGLE_RIGHT : ANGLE_LEFT;

            _currentBatAngle = Mathf.LerpUnclamped(from, to, batSwing.Evaluate(_swingTime));
            SetBatGrahpicsRotation(_currentBatAngle);

            Vector2 boxPos = batGraphics.TransformPoint(hitBoxOffset);

            int  numbHits     = Physics2D.OverlapBox(boxPos, hitBoxSize, _currentBatAngle, _contactFilter, _hitResults);
            bool hitSomething = false;
            for (int i = 0; i < numbHits; i++)
            {
                Collider2D hit = _hitResults[i];
                if (hit.attachedRigidbody != null && !_hitObjects.Contains(hit) && hit.gameObject != _playerController.gameObject)
                {
                    hit.attachedRigidbody.velocity = batPivot.right * 5f;
                    _hitObjects.Add(hit);
                    hitSomething = true;

                    playerController.HitSound();

                    batHitParticles.transform.position = hit.attachedRigidbody.transform.position - Vector3.forward * 5f;
                    batHitParticles.Play();
                }
            }
            if (hitSomething)
            {
                CameraShakerController.CameraShake();
            }

            if (_swingTime >= batSwing.Duration())
            {
                _swingTime = -1f;
                _isSwining = false;

                _hitObjects.Clear();


                if (_currentBatPos == BatPosition.Right)
                {
                    _playerController.playerAnimation.BatWobbleLeft();
                }
                else
                {
                    _playerController.playerAnimation.BatWobbleRight();
                }

                _currentBatPos = (BatPosition)(((int)_currentBatPos) * -1);
            }
        }
    }
コード例 #4
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Enemy"))
     {
         other.gameObject.GetComponent <EnemyBehaviour>().Die();
         CameraShakerController.CameraShake();
         DestroyMe();
     }
 }
コード例 #5
0
 public void Shake()
 {
     CameraShakerController.CameraShake();
     Instantiate(hit, transform.position, Quaternion.identity);
 }