Пример #1
0
 public void Update()
 {
     if (_npcCentral.GetConvinced())
     {
         if (_inputManager.GetInteract())
         {
             GameObject response = Instantiate(_response, transform.position, Quaternion.identity);
             response.transform.parent = transform;
         }
     }
 }
Пример #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);
                }
            }
        }
    }
Пример #3
0
    void Start()
    {
        _npcCentral = GetComponent <NpcCentral>();
        if (!_npcCentral)
        {
            Debug.Log("No NpcCentral here!");
        }

        _inputManager = FindObjectOfType <InputManager>().GetComponent <InputManager>();
        if (!_inputManager)
        {
            Debug.Log("No InputManager found!");
        }

        if (_npcCentral.GetConvinced())
        {
            GameObject response = Instantiate(_response, transform.position, Quaternion.identity);
            response.transform.parent = transform;
        }
        _gameData = FindObjectOfType <GameData>().GetComponent <GameData>();
    }