示例#1
0
    public void Update()
    {
        _Controller.SetHorizontalForce(_Direction.x * Speed);

        if ((_Direction.x < 0 && _Controller.State.isCollidingLeft) || (_Direction.x > 0 && _Controller.State.isCollidingRight))
        {
            _Direction           = -_Direction;
            transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);

            if ((_CanFireIn - Time.deltaTime) > 0)
            {
                return;
            }

            //add functionality to allow enemy to detect objects above them later!! EU 2/16/17

            var rayCast = Physics2D.Raycast(transform.position, _Direction, 10, 1 << LayerMask.NameToLayer("Player"));
            if (!rayCast)
            {
                return;
            }

            var projectile = (Projectile)Instantiate(Bullet, transform.position, transform.rotation);
            projectile.initialize(gameObject, _Direction, _Controller.Velocity);
            //end

            _CanFireIn = FireRate;
        }
    }
    public void Update()
    {
        if (!IsDead)
        {
            HandleInput();
        }

        PlayerAnim.state.SetAnimation(0, "FunnyIdle", true);

        var movementFactor = _Controller.State.isGrounded ? speedAccelerationGround : speedAccelerationAir;

        if (IsDead)
        {
            _Controller.SetHorizontalForce(0);
        }
        else
        {
            //    _Controller.SetHorizontalForce(Mathf.Lerp(_Controller.Velocity.x, movementFactor * maxSpeed, Time.deltaTime * movementFactor));
            _Controller.SetHorizontalForce(Mathf.Lerp(_Controller.Velocity.x, _normalizedHorizontalSpeed * maxSpeed, Time.deltaTime * movementFactor));
        }
    }