Exemple #1
0
    // Use this for initialization
    void Start()
    {
        inputManager           = GameManager.getInstance().getInputManager();
        weaponManager          = GameManager.getInstance().getWeaponManager();
        weaponSelectionManager = GameManager.getInstance().getWSelectionManager();

        //Creates a pool for weapons
        weaponManager.CreatePool(weaponSelectionManager.getMainWeapon(), 100);
        weaponManager.CreatePool(weaponSelectionManager.getAltWeapon(), 10);

        // If view is ours, attach us to the input manager
        if (photonView.isMine)
        {
            // Subscribe to all shooting input events
            inputManager.subscribeToInputGroup(EInputGroup.ShootingInput, this);
        }
    }
Exemple #2
0
    public void OnUserInputKeyDown(EInputGroup group, ICommand command)
    {
        if (command is ShootingCommand)
        {
            ShootingCommand shootingCommand = (ShootingCommand)command;
            //Parse target data
            Vector2 targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            Hand[]          allHands       = FindObjectsOfType <Hand>();
            Hand            hand           = allHands[allHands.Length - 1];
            PlayerCharacter player         = hand.GetComponentInParent <PlayerCharacter>();
            Vector2         playerVelocity = player.GetComponent <Rigidbody2D>().velocity;
            playerVelocity.Normalize();
            Vector2 handPos   = new Vector2(hand.transform.position.x, hand.transform.position.y);
            Vector2 direction = targetPos - handPos;

            //Normalize the vector for the adding of force
            direction.Normalize();

            Vector2 myPos = new Vector2(
                hand.transform.position.x + Mathf.Sign(direction.x) * (Mathf.Abs(direction.x) + 1) + (-.5f) * Math.Abs(playerVelocity.x),
                hand.transform.position.y + direction.y + playerVelocity.y
                );

            Quaternion rotation = Quaternion.Euler(0, 0, -90 + (Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg));

            switch (shootingCommand.control)
            {
            case EInputControls.ShootMain:
                // Instead of using the newRocket field, create a manager where you can get main and alt weapons, that have already been set up with the correct components
                // I.e. an empty projectile prefab, that a manager will attach a mover and an effect component to

                //Check for cooldown
                if (timeStampMain > Time.time)
                {
                    return;
                }

                weaponSelectionManager.getMainWeapon().GetComponent <AbsWeaponMover>().SetStartPosition(myPos);
                if (weaponSelectionManager.getMainWeaponName() == "newPellet")
                {
                    shootPellets(myPos, rotation, targetPos, handPos, direction);
                }
                else
                {
                    weaponManager.ReuseObject(weaponSelectionManager.getMainWeapon(), myPos, rotation, direction);
                }

                //Set cooldown
                timeStampMain = Time.time + weaponSelectionManager.getMainWeapon().GetComponent <AbsWeaponMover>().cooldownPeriod;
                break;

            case EInputControls.ShootAlt:

                //Check for cooldown
                if (timeStampAlt > Time.time)
                {
                    return;
                }

                weaponSelectionManager.getAltWeapon().GetComponent <AbsWeaponMover>().SetStartPosition(myPos);
                if (weaponSelectionManager.getAltWeaponName() == "newPellet")
                {
                    shootPellets(myPos, rotation, targetPos, handPos, direction);
                }
                else
                {
                    weaponManager.ReuseObject(weaponSelectionManager.getAltWeapon(), myPos, rotation, direction);
                }

                //Set cooldown
                timeStampAlt = Time.time + weaponSelectionManager.getAltWeapon().GetComponent <AbsWeaponMover>().cooldownPeriod;
                break;
            }
        }
    }