示例#1
0
 public void TryToConvince()
 {
     if (!_npcCentral.GetConvinced())
     {
         if (Random.Range(0, 100) < _convertionChance)
         {
             if (!_npcCentral.GetRepeled())
             {
                 _gameData.hp++;
                 GameObject response = Instantiate(_response, transform.position, Quaternion.identity);
                 response.transform.parent = transform;
                 _npcCentral.SetConvinced(true);
                 if (_reveal)
                 {
                     Instantiate(_reveal, transform.position, Quaternion.identity);
                     Destroy(gameObject);
                 }
             }
         }
         else
         {
             _npcCentral.SetRepeled(true);
         }
     }
 }
示例#2
0
    void FixedUpdate()
    {
        if (_npcCentral.GetConvinced())
        {
            float distance = _player.transform.position.x - transform.position.x;
            if (Mathf.Abs(distance) > _offset)
            {
                Vector2 movementVelocity = new Vector2(Mathf.Sign(distance) * _velocity, _rb.velocity.y);
                _rb.velocity = movementVelocity;

                _animator.SetFloat("speed", Mathf.Abs(movementVelocity.x));
                if (Mathf.Sign(movementVelocity.x) == -1)
                {
                    _spriteR.flipX = true;
                }
                else if (movementVelocity.x > 0)
                {
                    _spriteR.flipX = false;
                }
            }
            else
            {
                _animator.SetFloat("speed", 0);
            }
        }
        else
        {
            if (_npcCentral.GetRepeled())
            {
                if (_repeledTime > _timer)
                {
                    float   distance         = _player.transform.position.x - transform.position.x;
                    Vector2 movementVelocity = new Vector2(-1 * Mathf.Sign(distance) * _velocity * _repeledModifier, _rb.velocity.y);
                    _rb.velocity = movementVelocity;

                    _timer += Time.fixedDeltaTime;

                    _animator.SetFloat("speed", Mathf.Abs(movementVelocity.x));
                    if (Mathf.Sign(movementVelocity.x) == -1)
                    {
                        _spriteR.flipX = true;
                    }
                    else if (movementVelocity.x > 0)
                    {
                        _spriteR.flipX = false;
                    }
                }
                else
                {
                    _timer = 0;
                    _npcCentral.SetRepeled(false);
                    _animator.SetFloat("speed", 0);
                }
            }
        }
    }