Esempio n. 1
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        if (IsAlive())
        {
            float horizontal = Input.GetAxis("Horizontal");
            float vertical   = Input.GetAxis("Vertical");

            Vector2 mousePos = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));

            Move(horizontal, vertical);
            LookAt(mousePos.x, mousePos.y);

            if (weapon != null)
            {
                WeaponBehavior weaponScript = weapon.GetComponent <WeaponBehavior>();
                //TODO ajouter controls manager pour switch clavier/sourie (lastInput = clavier OU stick)
                Vector2 position = new Vector2(transform.position.x, transform.position.y);
                Vector2 direction;
                if (Input.GetMouseButton(0)) //PRESSED
                {
                    //Debug.Log("Pressed left.");
                    direction = mousePos - position;
                    weaponScript.Fire(this.gameObject, direction);
                }
                else
                {
                    direction = new Vector2(Input.GetAxis("RightStickX"), Input.GetAxis("RightStickY"));
                    if (direction.magnitude > 0)
                    {
                        weaponScript.Fire(this.gameObject, direction);
                    }
                }
            }

            if (Input.GetMouseButtonDown(1)) //CLICK
            {
                Debug.Log("Clicked right. ROULAAAAAADE");
            }

            /*if (Input.GetMouseButtonDown(2))
             *  Debug.Log("Clicked middle.");*/
        }
    }