예제 #1
0
    // Update is called once per frame
    void Update()
    {
        coolDown += Time.deltaTime;


        Physics.IgnoreLayerCollision(0, 11, (this.gameObject.GetComponent <CharacterController>().velocity.y > 0.0f));
        if (input.getFireEnabled() && coolDown > nextFire)
        {
            coolDown = 0.0f;
            if (input.updateMovement().x > 0) //rigth
            {
                rigth = false;
            }
            else if (input.updateMovement().x < 0)//left
            {
                rigth = true;
            }


            this.gameObject.transform.localScale = new Vector3(rigth ? -1 : 1, 1, 1);
            GameObject cloneBullet = (Network.peerType == NetworkPeerType.Disconnected) ? Instantiate(bullet, currentSourceTransform.position, Quaternion.identity) as GameObject
            : Network.Instantiate(bullet, currentSourceTransform.position, Quaternion.identity, 0) as GameObject;

            Bullet bulletObject = cloneBullet.gameObject.GetComponent <Bullet>();

            bulletObject.velocity = bulletVelocity;


            bulletObject.owner = this.gameObject.GetComponent <Life>().getTeam();

            bulletObject.toRight = rigth;
        }
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Inherited from an interface in case we want to do
        // more stuff. If it ends up being just one method, we can
        // simply implement it as a callback.
        Vector3 inputmovement = Vector3.zero;

        inputmovement = input.updateMovement();
        if (inputmovement != Vector3.zero)
        {
            _momentum.x += inputmovement.x * _acceleration;
        }
        if (inputmovement.y > 0)
        {
            jump();
        }
        _momentum.y -= _gravity;
        _momentum.x *= _velFriction * ((_isGrounded) ? Mathf.Abs(inputmovement.x) : 1);


        Vector3 oldPos = _transform.position;

        updateKinematicPhysics(controller.Move(_momentum * Time.fixedDeltaTime));
    }